Beispiel #1
0
        public static TicketModel InsertTicket(UserModel user)
        {
            // new ticket
            TicketProxy inTicketProxy = EmptyTicket();
            TicketModel ticket        = (TicketModel)Data_API.Create(user, inTicketProxy); // user created a ticketD

            TicketProxy outTicketProxy = Data_API.Read <TicketProxy>(ticket);

            Assert.AreEqual(inTicketProxy, outTicketProxy);

            // Actions
            ActionModel[] actions = new ActionModel[4];
            for (int j = 0; j < 4; ++j)
            {
                // new action
                ActionProxy inActionProxy = EmptyAction();
                actions[j] = Data_API.Create(ticket, inActionProxy) as ActionModel;
                Assert.AreEqual(actions[j], ticket.Action(actions[j].ActionID));
                ActionProxy outActionProxy = Data_API.Read <ActionProxy>(actions[j]);
                Assert.AreEqual(inActionProxy, outActionProxy);
            }

            ActionModel[] readActions = ticket.Actions();
            CollectionAssert.AreEqual(actions, readActions);

            return(ticket);
        }
        public void ActionAttachments()
        {
            string userData = _userScot;
            AuthenticationModel authentication = AuthenticationModel.AuthenticationModelTest(userData, _connectionString);

            using (ConnectionContext connection = new ConnectionContext(authentication))
            {
                // user ticket
                TicketProxy ticketProxy = IDTreeTest.EmptyTicket();                                   // from front end
                TicketModel ticketModel = (TicketModel)Data_API.Create(connection.User, ticketProxy); // dbo.Tickets

                // ticket action
                ActionProxy actionProxy = IDTreeTest.EmptyAction();                               // from front end
                ActionModel actionModel = (ActionModel)Data_API.Create(ticketModel, actionProxy); // dbo.Actions

                // action attachment
                ActionAttachmentProxy attachmentProxy = (ActionAttachmentProxy)IDTreeTest.CreateAttachment(connection.OrganizationID,
                                                                                                           AttachmentProxy.References.Actions, actionModel.ActionID, actionModel.AttachmentPath);
                AttachmentModel attachmentModel = (AttachmentModel)Data_API.Create(actionModel, attachmentProxy);

                // read back attachment
                AttachmentProxy read = Data_API.ReadRefTypeProxy <AttachmentProxy>(connection, attachmentProxy.AttachmentID);
                switch (read)
                {
                case ActionAttachmentProxy output:      // Action attachment
                    Assert.AreEqual(attachmentProxy, output);
                    break;

                default:
                    Assert.Fail();
                    break;
                }
            }
        }
Beispiel #3
0
        public void Intercepte(ActionProxy actionProxy)
        {
            logger.Debug("exception interceptor, order:" + Order);
            try
            {
                actionProxy.Execute();
            }
            catch (Exception ex)
            {
                logger.Error("ExceptionInterceptor:", ex);

                string        subject = "Action Error, ActionId = " + actionId + ", Exception = " + ex.GetType().Name;
                StringBuilder mesasge = new StringBuilder();
                mesasge.Append("ActionId=").AppendLine(actionId)
                .Append("Environment=").AppendLine(Environment.MachineName)
                .Append("Exception Message=").AppendLine(ex.Message)
                .Append("Exception Trace=").AppendLine(ex.StackTrace)
                .Append("Exception Source=").AppendLine(ex.Source);
                string        from = notifier;
                List <string> to   = notifiedGroups.ToList();

                mailManager.BeginSend(subject, mesasge.ToString(), from, null, to, null, null);
                throw;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Executes a specified action proxy from an addon.
        /// </summary>
        /// <param name="actionProxy">The <see cref="ActionProxy"/> to execute.</param>
        /// <param name="timeout">The action execution timeout (in milliseconds).</param>
        /// <returns>The response from the Agent upon executing the action proxy.</returns>
        public ActionExecutionResponse ExecuteProxy(ActionProxy actionProxy, int timeout)
        {
            RestRequest sendActionProxyRequest = new RestRequest(Endpoints.EXECUTE_ACTION_PROXY, Method.POST);

            sendActionProxyRequest.RequestFormat = DataFormat.Json;

            string json = CustomJsonSerializer.ToJson(actionProxy.ProxyDescriptor, this.serializerSettings);

            sendActionProxyRequest.AddJsonBody(json);

            if (timeout > 0)
            {
                // Since action proxy execution can take a while, you can override the default timeout.
                this.client.Timeout = timeout;
            }

            IRestResponse sendActionProxyResponse = this.client.Execute(sendActionProxyRequest);

            if (sendActionProxyResponse.StatusCode.Equals(HttpStatusCode.NotFound))
            {
                string errorMessage = $"Action {actionProxy.ProxyDescriptor.ClassName} in addon {actionProxy.ProxyDescriptor.Guid} is not installed for your account.";

                Logger.Error(errorMessage);
                throw new AddonNotInstalledException(errorMessage);
            }

            // Reset the client timeout to the RestSharp default.
            this.client.Timeout = this.defaultRestClientTimeoutInMilliseconds;

            return(CustomJsonSerializer.FromJson <ActionExecutionResponse>(sendActionProxyResponse.Content, this.serializerSettings));
        }
Beispiel #5
0
        public void ShouldOperateOnInterface()
        {
            var harness = new StringHarness();
            var proxy   = ActionProxy <ITestAction> .Create("testActionName", "netsh unittest", harness);

            proxy.SimpleMethod();
            Assert.AreEqual("netsh unittest testActionName SimpleMethod", harness.Value);
        }
Beispiel #6
0
        public void ShouldSupportParameterNameDecoratedMethods()
        {
            var harness = new StringHarness();
            var proxy   = ActionProxy <ITestAction> .Create("testActionName", "netsh unittest", harness);

            proxy.MethodWithParameterNameDecoration("myParameterTest");
            Assert.AreEqual("netsh unittest testActionName MethodWithParameterNameDecoration test=myParameterTest", harness.Value);
        }
        public bool AddMenuItem(string pluginName, string cmd, ActionProxy callback)
        {
            if (pluginName.IsNullOrEmpty() || cmd.IsNullOrEmpty())
            {
                return(false);
            }

            return(Svc <DevContextMenuPlugin> .Plugin.AddMenuItem(pluginName, cmd, callback));
        }
Beispiel #8
0
        public bool AddMenuItem(string pluginName, string cmd, ActionProxy callback)
        {
            if (pluginName.IsNullOrEmpty() || cmd.IsNullOrEmpty())
            {
                return(false);
            }

            PluginCmdActionMap[cmd] = callback;
            return(true);
        }
Beispiel #9
0
        public void ShouldSupportEnumTypeDecoratedParameters()
        {
            var harness = new StringHarness();
            var proxy   = ActionProxy <ITestAction> .Create("testActionName", "netsh unittest", harness);

            proxy.MethodWithDecoratedEnum(DecoratedEnum.Value1);
            Assert.AreEqual("netsh unittest testActionName MethodWithDecoratedEnum testEnum=value1", harness.Value);
            proxy.MethodWithDecoratedEnum(DecoratedEnum.Value2);
            Assert.AreEqual("netsh unittest testActionName MethodWithDecoratedEnum testEnum=value2", harness.Value);
        }
Beispiel #10
0
        public void ShouldSupportBooleanDescriptionDecoratedEnumerations()
        {
            var harness = new StringHarness();
            var proxy   = ActionProxy <ITestAction> .Create("testActionName", "netsh unittest", harness);

            proxy.MethodWithEnum(TestEnum.Value1);
            Assert.AreEqual("netsh unittest testActionName MethodWithEnum testEnum=Value1", harness.Value);
            proxy.MethodWithEnum(TestEnum.Value2);
            Assert.AreEqual("netsh unittest testActionName MethodWithEnum testEnum=Value2", harness.Value);
        }
Beispiel #11
0
        public void ShouldCallIRequestProcessor()
        {
            var harness = new Mock <IExecutionHarness>();
            var proxy   = ActionProxy <ITestAction> .Create("test", "netsh unittest", harness.Object);

            var response = proxy.SimpleResponseMethod();

            Assert.IsNotNull(response);
            Assert.IsInstanceOfType(response, typeof(StandardResponse));
        }
Beispiel #12
0
        public void ShouldSupportEnumerationParameters()
        {
            var harness = new StringHarness();
            var proxy   = ActionProxy <ITestAction> .Create("testActionName", "netsh unittest", harness);

            proxy.MethodWithNull();
            Assert.AreEqual("netsh unittest testActionName MethodWithNull", harness.Value);
            proxy.MethodWithNull(1);
            Assert.AreEqual("netsh unittest testActionName MethodWithNull testInt=1", harness.Value);
        }
Beispiel #13
0
        public void ShouldSupportBooleanTypeDecoratedParameters()
        {
            var harness = new StringHarness();
            var proxy   = ActionProxy <ITestAction> .Create("testActionName", "netsh unittest", harness);

            proxy.MethodWithBooleanTypeYesNo(true, false, true);
            Assert.AreEqual("netsh unittest testActionName MethodWithBooleanTypeYesNo testBooleanYesNo=yes testBooleanEnableDisable=disable testBooleanTrueFalse=true", harness.Value);
            proxy.MethodWithBooleanTypeYesNo(false, true, false);
            Assert.AreEqual("netsh unittest testActionName MethodWithBooleanTypeYesNo testBooleanYesNo=no testBooleanEnableDisable=enable testBooleanTrueFalse=false", harness.Value);
        }
Beispiel #14
0
        public void ShouldCallExecutionHarness()
        {
            var harness = new Mock <IExecutionHarness>();
            var proxy   = ActionProxy <ITestAction> .Create("test", "netsh unittest", harness.Object);

            proxy.SimpleMethod();
            int exitCode;

            harness.Verify(x => x.Execute(It.IsAny <String>(), out exitCode), Times.Once());
        }
Beispiel #15
0
    static void Main(string[] args)
    {
        {
            Action action = () => { Console.WriteLine("Action"); };
            ActionProxy <Action> proxy = new ActionProxy <Action>(action);
            proxy.Call();
        }

        {
            Action <int> action = (arg) => { Console.WriteLine($"Action<int>: {arg}"); };
            ActionProxy <Action <int> > proxy = new ActionProxy <Action <int> >(action);
            proxy.Call();
        }

        {
            EnumValueCache <Days> days = new EnumValueCache <Days>();

            Console.WriteLine(days.GetInteger(Days.Friday));
            Console.WriteLine(days.GetInteger(Days.Thursday));
        }

        unsafe
        {
            int n = 10;
            using (UnmanagedWrapper <int> intArray = new UnmanagedWrapper <int>(n))
            {
                for (int i = 0; i < n; i++)
                {
                    intArray[i] = i;
                }

                for (int i = 0; i < n; i++)
                {
                    Console.Write(intArray[i] + ",");
                }
            }
        }

        unsafe
        {
            int n = 10;
            using (UnmanagedWrapper <long> longArray = new UnmanagedWrapper <long>(n))
            {
                for (int i = 0; i < n; i++)
                {
                    longArray[i] = i;
                }

                for (int i = 0; i < n; i++)
                {
                    Console.Write(longArray[i] + ",");
                }
            }
        }
    }
Beispiel #16
0
 private void FromProxy(ActionProxy proxy)
 {
     this.Id                      = proxy.Id;
     this._kind                   = proxy.Kind;
     this._exportFormatKey        = proxy.ExportFormatKey;
     this._outputFileName         = proxy.OutputFileName;
     this._exportFormatName       = proxy.ExportFormatName;
     this._exportDefaultExtension = proxy.ExportDefaultExtension;
     this._message                = proxy.Message;
     this._checkedStatus          = proxy.CheckedStatus;
     this._exportFormatNames      = proxy.ExportFormatNames;
     this._actionKinds            = proxy.ActionKinds;
 }
Beispiel #17
0
        public string PerfomAction(string action, string prm1 = "", string prm2 = "")
        {
            var request = new ActionProxy
            {
                Req  = action,
                Prm1 = prm1,
                Prm2 = prm2,
                Rsp  = ""
            };

            var reply = grpcService.ClientCRUDs.PerformAction(request);  // --------->

            return(reply.Rsp);
        }
Beispiel #18
0
        public static object ConvertAction(Action <object> action, Type type)
        {
            if (action == null)
            {
                return(null);
            }

            ActionProxy ap = new ActionProxy(action);
            var         makeGenericType = typeof(Action <>).MakeGenericType(type);
            var         methodInfo      = typeof(ActionProxy).GetMethod("Invoke").MakeGenericMethod(type);
            var         @delegate       = Delegate.CreateDelegate(makeGenericType, ap, methodInfo);

            return(@delegate);
        }
Beispiel #19
0
        private ActionProxy ToProxy()
        {
            ActionProxy proxy = new ActionProxy();

            proxy.Id                     = this.Id;
            proxy.Kind                   = this.Kind;
            proxy.ExportFormatKey        = this.ExportFormatKey;
            proxy.OutputFileName         = this.OutputFileName;
            proxy.ExportFormatName       = this.ExportFormatName;
            proxy.ExportDefaultExtension = this.ExportDefaultExtension;
            proxy.Message                = this.Message;
            proxy.CheckedStatus          = this.CheckedStatus;
            proxy.ExportFormatNames      = this.ExportFormatNames;
            proxy.ActionKinds            = this.ActionKinds;
            return(proxy);
        }
        public void Intercepte(ActionProxy actionProxy)
        {
            logger.Debug("logging interceptor, order:" + Order);

            ActionLog actionLog = new ActionLog();

            actionLog.ActionId  = actionId;
            actionLog.StartDate = DateTime.Now;
            actionLog.Status    = "Start";

            if (actionLogger is FileLogger)
            {
                string logFile = CreateLogFilePath(actionLog);
                ((FileLogger)actionLogger).SetLogFile(logFile);
                actionLog.LogPath = logFile;
            }

            actionLogger.Log("Start Executing Action, actionId=" + actionId +
                             ", Environment=" + Environment.MachineName + ", PID=" + Process.GetCurrentProcess().Id);

            actionLogData.CreateActionLog(actionLog);

            try
            {
                actionProxy.Execute();
                actionLog.Status = "Success";
                actionLogger.Log("Finish Executing Action");
            }
            catch (Exception ex)
            {
                actionLog.Status = "Fail";
                actionLogger.Log("Failed Executing Action", ex);
                throw;
            }
            finally
            {
                actionLog.EndDate = DateTime.Now;
                actionLogData.CompleteActionLog(actionLog);

                actionLogger.Flush();
            }
        }
Beispiel #21
0
        // Global Actions
        public override Task <ActionProxy> PerformAction(ActionProxy request, ServerCallContext context)
        {
            Scheduling.RunTask(() =>
            {
                if (request.Req == "RefreshSonucDnmRun")
                {
                    H.MAC_RefreshSonuc(H.DnmRun);
                    H.CET_RefreshSonuc(H.DnmRun);
                    H.CT_RefreshSonuc(H.DnmRun);
                    H.CTP_RefreshSonuc(H.DnmRun);
                    H.DD_RefreshSonuc(H.DnmRun);
                    H.PPRD_RefreshSonuc(H.DnmRun);
                    H.PPRD_RefreshCurRuns(H.DnmRun);

                    H.CEF_RefreshSonuc();   // Bunlari da Donem/Sezon luk yap.
                    H.CF_RefreshSonuc();

                    request.Rsp = "";
                }
                else if (request.Req == "CreateEvents")
                {
                    ulong CCoNo = ulong.Parse(request.Prm1);
                    CC cc       = Db.FromId <CC>(CCoNo);
                    if (cc.Skl == "F")
                    {
                        request.Rsp = H.CEF_CreateEvents(CCoNo);
                    }
                    else if (cc.Skl == "T")
                    {
                        request.Rsp = H.CET_CreateEvents(CCoNo);
                    }
                }
            }).Wait();

            Session.RunTaskForAll((s, id) =>
            {
                s.CalculatePatchAndPushOnWebSocket();
            });

            return(Task.FromResult(request));
        }
Beispiel #22
0
        /// <summary>
        /// CREATE
        /// </summary>
        public static void Create <T>(T proxy)
        {
            try
            {
                using (ConnectionContext connection = new ConnectionContext())
                {
                    switch (typeof(T).Name)
                    {
                    case "ActionProxy":
                    {
                        ActionProxy actionProxy = proxy as ActionProxy;
                        Data_API.Create(connection.Ticket(actionProxy.TicketID), actionProxy);
                    }
                    break;

                    case "AttachmentProxy":
                    {
                        AttachmentProxy        attachment = proxy as AttachmentProxy;
                        IAttachmentDestination model      = AttachmentAPI.ClassFactory(connection, attachment);
                        Data_API.Create(model as IDNode, attachment);
                    }
                    break;

                    default:
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                // TODO - tell user we failed to read
                Data_API.LogMessage(ActionLogType.Insert, ReferenceType.None, 0, "choke", ex);
            }
        }
Beispiel #23
0
        /// <summary>
        /// UPDATE
        /// </summary>
        public static void Update <T>(T proxy)
        {
            try
            {
                using (ConnectionContext connection = new ConnectionContext())
                {
                    switch (typeof(T).Name)
                    {
                    case "ActionProxy":
                        ActionProxy actionProxy = proxy as ActionProxy;
                        //DataAPI.DataAPI.Update(new ActionNode(connection, actionProxy.ActionID), actionProxy);
                        break;

                    case "AttachmentProxy":
                        AttachmentProxy attachmentProxy = proxy as AttachmentProxy;
                        UpdateArguments args            = new UpdateArguments();
                        args.Append("FileName", attachmentProxy.FileName);
                        args.Append("Path", attachmentProxy.Path);
                        args.Append("FilePathID", attachmentProxy.FilePathID.Value);
                        Data_API.Update(new AttachmentModel(connection, attachmentProxy), args);
                        break;

                    default:
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                // TODO - tell user we failed to read
                //int logid = DataAPI.Data_API.LogException(connection.Authentication, ex, "Ticket Merge Exception:" + ex.Source);
                //return $"Error merging tickets. Exception #{logid}. Please report this to TeamSupport by either emailing [email protected], or clicking Help/Support Hub in the upper right of your account.";
            }
        }
 public void Intercepte(ActionProxy actionProxy)
 {
     logger.Info("SampleActionInterceptor, order:" + Order);
     actionProxy.Execute();
 }