Exemple #1
0
        /// <summary>
        /// Sets the handler that should be called when this operation is invoked
        /// </summary>
        /// <param name="roleName">The name of the role that contains the operation</param>
        /// <param name="opName">The name of the operation whose handler is being set</param>
        /// <param name="handler">The handler to call</param>
        public void SetOperationDelegate(string roleName, string opName, OperationDelegate handler)
        {
            OperationKey roleOpPair = new OperationKey(opName);

            bool operationFound = false;

            //check if this role/op pair exists for the port
            foreach (HomeOS.Hub.Platform.Views.VRole role in portInfo.GetRoles())
            {
                if (roleName.Equals(role.Name(), StringComparison.CurrentCultureIgnoreCase))
                {
                    foreach (HomeOS.Hub.Platform.Views.VOperation operation in role.GetOperations())
                    {
                        if (opName.Equals(operation.Name(), StringComparison.CurrentCultureIgnoreCase))
                        {
                            operationFound = true;
                            break;
                        }
                    }
                }
            }

            if (!operationFound)
            {
                throw new InvalidOperationException("Assigning delegate " + handler + " to non-existent role/operation " + roleOpPair.ToString());
            }

            this.operationDelegates[roleOpPair] = handler;
        }
Exemple #2
0
        void ApplyOperation(
            UnitOfWorkAction action, IList <IDomainObject> affectedEntities,
            SuccessfulUoWInvocationDelegate successfulInvocation, FailedUoWInvocationDelegate failedInvocation
            )
        {
            for (int index = 0; index < affectedEntities.Count; index++)
            {
                IDomainObject entity = affectedEntities[index];

                if (entity == null)
                {
                    continue;
                }

                IBaseMapper       mapper    = entity.Mapper;
                OperationDelegate operation = GetOperation(action, mapper);

                bool success = operation(ref entity,
                                         (domainObject, results) =>
                {
                    if (successfulInvocation != null)
                    {
                        successfulInvocation(domainObject, action, results);
                    }
                },
                                         (domainObject, results) =>
                {
                    if (failedInvocation != null)
                    {
                        failedInvocation(domainObject, action, results);
                    }
                });
            }
        }
Exemple #3
0
 public ParseSingleResultMiddleware(
     OperationDelegate next,
     IEnumerable <IResultParser> resultParsers)
 {
     _next          = next ?? throw new ArgumentNullException(nameof(next));
     _resultParsers = resultParsers.ToDictionary();
 }
Exemple #4
0
 public CreateStandardRequestMiddleware(
     OperationDelegate next,
     IOperationSerializer serializer)
 {
     _next       = next ?? throw new ArgumentNullException(nameof(next));
     _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
 }
Exemple #5
0
 public Operation(string N, Type TL, OperationDelegate DEL)
 {
     Name      = N;
     TypeLeft  = TL;
     TypeRight = null;
     operation = DEL;
 }
Exemple #6
0
        /// <summary>
        ///     Executes an index opeation.
        /// </summary>
        public SkryptObject ExecuteIndex(IndexNode node, ScopeContext scopeContext)
        {
            var arguments = new List <SkryptObject>();

            foreach (var subNode in node.Arguments)
            {
                var result = ExecuteExpression(subNode, scopeContext);

                arguments.Add(result);
            }

            var Object = ExecuteExpression(node.Getter, scopeContext);

            // Dynamically change type so we can get it's actual operations.
            dynamic left = Convert.ChangeType(Object, Object.GetType());

            Operation opLeft = SkryptObject.GetOperation(Operators.Index, Object.GetType(), arguments[0].GetType(), left.Operations);

            OperationDelegate operation = null;

            if (opLeft != null)
            {
                operation = opLeft.OperationDelegate;
            }
            else
            {
                _engine.ThrowError("No such operation as index " + left.Name + "!", node.Getter.Token);
            }

            var inputArray = new List <SkryptObject>(arguments);

            inputArray.Insert(0, Object);

            return(operation(inputArray.ToArray(), _engine));
        }
Exemple #7
0
        /// <summary>
        /// Invoke the operation
        /// </summary>
        /// <param name="operation">indicating the operation delegate</param>
        /// <param name="onException">indicating the delegate to handle exception</param>
        /// <param name="retryCount">indicating the max retry count</param>
        /// <returns>returns result</returns>
        public static T InvokeOperation(OperationDelegate operation, ExceptionThrownDelegate onException, RetryPolicy policy)
        {
            int       retry         = policy.RetryCount;
            Exception lastException = null;

            while (retry > 0)
            {
                try
                {
                    return(operation());
                }
                catch (Exception e)
                {
                    lastException = e;
                    onException(e, retry);

                    if (!policy.NoIncreaseRetryCountExceptionList.Contains(e.GetType()))
                    {
                        retry--;
                    }
                }
            }

            throw lastException;
        }
Exemple #8
0
        /// <summary>
        /// Shows result of operation
        /// </summary>
        /// <param name="num1">first number</param>
        /// <param name="num2">second number</param>
        /// <param name="operation">operation</param>
        static void ShowOperationResult(double num1, double num2, string operation)
        {
            OperationDelegate op = null;

            switch (operation)
            {
            case "+":
                op = (a, b) => { return(a + b); };    // Add
                break;

            case "-":
                op = (a, b) => { return(a - b); };    // Sub
                break;

            case "*":
                op = (a, b) => { return(a * b); };    // Mul
                break;

            case "/":
                op = (a, b) =>
                {
                    return(b != 0 ? a / b : double.PositiveInfinity);    // Div
                };
                break;

            default:
                Console.WriteLine("Unknown operation!");
                break;
            }
            // If we dont return result of operation, op = null => Exception
            if (op != null)
            {
                Console.WriteLine($"Result = {op(num1, num2)}.");
            }
        }
    private static void NotifyClients <T>(OperationDelegate <T> operationDelegate, Operation op, T obj)
    {
        if (operationDelegate == null)
        {
            return;
        }

        Delegate[] invkList = operationDelegate.GetInvocationList();

        foreach (OperationDelegate <T> handler in invkList)
        {
            new Thread(() =>
            {
                try
                {
                    handler(op, obj);
                    Console.WriteLine("Invoking event handler");
                }
                catch (Exception)
                {
                    operationDelegate -= handler;
                    Console.WriteLine("Exception: Removed an event handler");
                }
            }).Start();
        }
    }
 public Operation(Operators o, Type tl, OperationDelegate del)
 {
     Operator          = o;
     TypeLeft          = tl;
     TypeRight         = null;
     OperationDelegate = del;
 }
Exemple #11
0
 public CreateStandardRequestMiddleware(
     OperationDelegate next,
     IOperationFormatter formatter)
 {
     _next      = next ?? throw new ArgumentNullException(nameof(next));
     _formatter = formatter ?? throw new ArgumentNullException(nameof(formatter));
 }
        public void AddButton(string text, string toolTipText = "",
                              OperationDelegate operation     = null,
                              Image image   = null,
                              bool showText = true
                              )
        {
            ToolStripButton tsb = new ToolStripButton();

            tsb.Click       += MenuItem_Click;
            tsb.DisplayStyle = ToolStripItemDisplayStyle.Text;
            tsb.Text         = text;
            tsb.ToolTipText  = string.IsNullOrEmpty(toolTipText) ? text : toolTipText;
            tsb.Name         = GenerateName(text);
            if (image != null)
            {
                tsb.Image = image;
                if (showText)
                {
                    tsb.DisplayStyle      = ToolStripItemDisplayStyle.ImageAndText;
                    tsb.TextImageRelation = TextImageRelation.ImageBeforeText;
                }
                else
                {
                    tsb.DisplayStyle = ToolStripItemDisplayStyle.Image;
                }
            }

            AddUserItem(tsb);

            if (operation != null)
            {
                operations.Add(tsb.Name, operation);
            }
        }
        static void Main(string[] args)
        {
            OperationDelegate OD = Operation.Add;

            OD += Operation.Mul;

            OD(10, 20);
        }
Exemple #14
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="webBrowserReceiver">コントロールクラスのインスタンス</param>
        public Operation(WebBrowserReceiver webBrowserReceiver, bool moveWaitFlag)
        {
            this.webBrowserReceiver = webBrowserReceiver;

            this.moveWaitFlag = moveWaitFlag;

            operationDelegate = new OperationDelegate(doneImpl);
        }
Exemple #15
0
        public readonly float Delay;              //Its depend on weight of the items being moved

        public DelayedOperation(float delay, OperationDelegate onOperationComplete,
                                TickDelegate onTimerTick = null,
                                OperationDelegate onOperationCancelled = null)
        {
            this.Delay           = delay;
            OnOperationComplete  = onOperationComplete;
            OnTimerTick          = onTimerTick ?? (value => { UIController.Instance.OperationBarUI.fillAmount = value; });
            OnOperationCancelled = onOperationCancelled ?? (() => { UIController.Instance.OperationBarUI.fillAmount = 0; });
        }
Exemple #16
0
 public Operation(string name, OperationDelegate method,
                  bool hasBranch = false, bool hasStore = false, bool hasText = false)
 {
     Name      = name;
     Method    = method;
     HasBranch = hasBranch;
     HasStore  = hasStore;
     HasText   = hasText;
 }
Exemple #17
0
        private void RowOperation(OperationDelegate function, Row row, IEnumerable <bool> bits)
        {
            int x = 0;

            foreach (bool bit in bits)
            {
                this[GetIndex(x, row.Y, row.Z)] = function(x, row.Y, row.Z, bit);
                x++;
            }
        }
Exemple #18
0
        private void LaneOperation(OperationDelegate function, Lane lane, IEnumerable <bool> bits)
        {
            int z = 0;

            foreach (bool bit in bits)
            {
                this[GetIndex(lane.X, lane.Y, z)] = function(lane.X, lane.Y, z, bit);
                z++;
            }
        }
Exemple #19
0
        private void ColumnOperation(OperationDelegate function, Column column, IEnumerable <bool> bits)
        {
            int y = 0;

            foreach (bool bit in bits)
            {
                this[GetIndex(column.X, y, column.Z)] = function(column.X, y, column.Z, bit);
                y++;
            }
        }
        private void Modify(RichTextBox control, OperationDelegate op)
        {
            string currentText = control.SelectedText.TrimEnd();
            string content     = currentText;

            if (op != null)
            {
                content = op(currentText);
            }

            Modify(richTextBox1, content);
        }
 public HttpOperationExecutor(
     Func <HttpClient> clientFactory,
     OperationDelegate executeOperation,
     IServiceProvider services)
 {
     _clientFactory = clientFactory
                      ?? throw new ArgumentNullException(nameof(clientFactory));
     _executeOperation = executeOperation
                         ?? throw new ArgumentNullException(nameof(executeOperation));
     _services = services
                 ?? throw new ArgumentNullException(nameof(services));
 }
 public HttpOperationExecutor(
     HttpClient client,
     OperationDelegate executeOperation,
     IServiceProvider services)
 {
     _client = client
               ?? throw new ArgumentNullException(nameof(client));
     _executeOperation = executeOperation
                         ?? throw new ArgumentNullException(nameof(executeOperation));
     _services = services
                 ?? throw new ArgumentNullException(nameof(services));
 }
Exemple #23
0
        static void Main(string[] args)
        {
            OperationDelegate
                obj = Multicast.Add;

            obj += Multicast.Square;

            obj(2);
            obj(8);

            Console.ReadLine();
        }
        private void MenuItem_Click(object sender, EventArgs e)
        {
            string buttonText = GetButtonText(sender);

            if (operations.ContainsKey(buttonText))
            {
                OperationDelegate op = operations[buttonText];

                Modify(richTextBox1, op);
                Show();
            }
        }
Exemple #25
0
        /// <summary>
        /// Binds the port to the list of roles and sets the delegate for all operations in each role
        /// </summary>
        /// <param name="port">The port to bind</param>
        /// <param name="roles">The list of roles to bind</param>
        /// <param name="opDelegate">The delegate for all operations</param>
        protected void BindRoles(Port port, List <VRole> roles, OperationDelegate opDelegate)
        {
            platform.SetRoles(port.GetInfo(), roles, this);

            foreach (VRole role in roles)
            {
                foreach (VOperation operation in role.GetOperations())
                {
                    port.SetOperationDelegate(role.Name(), operation.Name(), opDelegate);
                }
            }
        }
Exemple #26
0
        public Operation(T val1, T val2)
        {
            _val1 = val1;
            _val2 = val2;

            Calculator <T> calculator = new Calculator <T>();

            Add   += calculator.Sum;
            Subtr += calculator.Difference;
            Mult  += calculator.Multiplication;
            Div   += calculator.Division;
        }
        public void BeginOperate(Form parentForm, OperationDelegate operationMethod)
        {
            /*
            _Operation = operationMethod;
            if (operationMethod == null)
                return;

            //operationMethod();
            Thread thread = new Thread(new ThreadStart(this.BeginOperate));
            thread.Start();
            */
            BeginOperate(parentForm, operationMethod, null);
        }
Exemple #28
0
 public void BeginOperate(Form parentForm, OperationDelegate operationMethod)
 {
     /*
      * _Operation = operationMethod;
      * if (operationMethod == null)
      *  return;
      *
      *
      * //operationMethod();
      * Thread thread = new Thread(new ThreadStart(this.BeginOperate));
      * thread.Start();
      */
     BeginOperate(parentForm, operationMethod, null);
 }
 public void BeginOperate(Form parentForm, OperationDelegate operationMethod, string waitingText)
 {
     if (!string.IsNullOrEmpty(waitingText))
     {
         this.WaitingText = waitingText;
     }
     if (operationMethod == null)
         return;
     _Operation = operationMethod;
     Thread thread = new Thread(new ThreadStart(this.BeginOperate));
     thread.Priority = ThreadPriority.AboveNormal;
     thread.Start();
     this.ShowDialog(parentForm);
 }
 public HttpOperationExecutor(
     Func <HttpClient> clientFactory,
     OperationDelegate <IHttpOperationContext> executeOperation,
     IOperationFormatter operationFormatter,
     IResultParserCollection resultParserResolver)
 {
     _clientFactory = clientFactory
                      ?? throw new ArgumentNullException(nameof(clientFactory));
     _executeOperation = executeOperation
                         ?? throw new ArgumentNullException(nameof(executeOperation));
     _operationFormatter = operationFormatter
                           ?? throw new ArgumentNullException(nameof(operationFormatter));
     _resultParserResolver = resultParserResolver
                             ?? throw new ArgumentNullException(nameof(resultParserResolver));
 }
Exemple #31
0
        private void SliceOperation(OperationDelegate function, Slice slice, IEnumerable <bool> bits)
        {
            int x = 0;
            int y = 0;

            foreach (bool bit in bits)
            {
                this[GetIndex(x, y, slice.Z)] = function(x, y, slice.Z, bit);
                if (++x == 5)
                {
                    x = 0;
                    y++;
                }
            }
        }
Exemple #32
0
        private void SheetOperation(OperationDelegate function, Sheet sheet, IEnumerable <bool> bits)
        {
            int w = _size.W;
            int y = 0;
            int z = 0;

            foreach (bool bit in bits)
            {
                this[GetIndex(sheet.X, y, z)] = function(sheet.X, y, z, bit);
                if (++z == w)
                {
                    z = 0;
                    y++;
                }
            }
        }
Exemple #33
0
 /// <summary>
 /// Initializes a new instance of the RasterMagic class.
 /// </summary>
 public RasterMagic(OperationDelegate operation)
 {
     Operation = operation;
 }
        private static CoolMatrix PerformOperation(CoolMatrix leftMatrix, CoolMatrix rightMatrix, OperationDelegate operationDelegate)
        {
            if (leftMatrix.Size != rightMatrix.Size) throw new ArgumentException();

            var tempMatrix = new CoolMatrix(leftMatrix);

            for (var i = 0; i < leftMatrix.Size.Width; i++)
            {
                for (var j = 0; j < leftMatrix.Size.Height; j++)
                {
                    tempMatrix[i, j] = operationDelegate(leftMatrix[i, j], rightMatrix[i, j]);
                }
            }
            return tempMatrix;
        }
        private static CoolMatrix PerformOperation(CoolMatrix matrix, int number, OperationDelegate operationDelegate)
        {
            var tempMatrix = new CoolMatrix(matrix);

            for (var i = 0; i < matrix.Size.Width; i++)
            {
                for (var j = 0; j < matrix.Size.Height; j++)
                {
                    tempMatrix[i, j] = operationDelegate(matrix[i, j], number);
                }
            }
            return tempMatrix;
        }
    void NotifyWorkers(Operations op, Order order, OperationDelegate wd)
    {
        if (wd != null)
        {
            Delegate[] invkList = wd.GetInvocationList();

            foreach (OperationDelegate handler in invkList)
            {
                try
                {
                    IAsyncResult ar = handler.BeginInvoke(op, order, null, null);
                    Console.WriteLine("Invoking event handler");
                }
                catch (Exception)
                {
                    wd -= handler;
                }
            }
        }
    }