Example #1
0
 public LanDeskItem AddPrivateNote(LanDeskItem ldi, string message)
 {
     ldi.Success = false;
     ExecuteFunction(ldi, "AddPrivateNote", message);
     ldi.Success = true;
     return(ldi);
 }
Example #2
0
        public IEnumerable <LanDeskItem> GetLanDeskItemsOfTypesForAssignedGroupsAndLatestUpdate(string[] types, string[] teams, int minutesPassed)
        {
            foreach (var typeString in types)
            {
                var type = new LanDeskItemType(typeString);
                foreach (var team in teams)
                {
                    const string format      = "MM/dd/yyyy hh:mm:ss tt";
                    var          strDate     = DateTime.Now.AddMinutes(minutesPassed).ToString(format);
                    CultureInfo  en          = new CultureInfo("en-US");
                    var          parsedBack  = DateTime.ParseExact(strDate, format, en.DateTimeFormat);
                    var          dateParsed  = parsedBack.ToString();
                    var          lanDeskItem = new LanDeskItem {
                        Type = type, attributes = { _CurrentAssignedGroup = team, LastUpdate = dateParsed }
                    };
                    var cn = new BooleanCondition
                    {
                        Condition1 = new Condition

                        {
                            Operator = Operator.Equals,
                            Property = "_CurrentAssignedGroup",
                            Variable = lanDeskItem.attributes._CurrentAssignedGroup
                        },
                        ConditionType = ConditionType.And,
                        Condition2    = new Condition
                        {
                            Operator = Operator.GreaterThan,
                            Property = "LastUpdate",
                            Variable = lanDeskItem.attributes.LastUpdate
                        }
                    };
                    var query        = new QueryBuilder(lanDeskItem.Type);
                    var fullQuery    = query.CreateQuery(0, lanDeskItem.Type.AvailableProperties[0], cn, lanDeskItem.Type.AvailableProperties.Take(30).ToArray());
                    var queryResults = ToLanDesk(ExecuteQuery, fullQuery);
                    if (queryResults == null)
                    {
                        continue;
                    }
                    foreach (var res in queryResults)
                    {
                        var queryItem = GetLanDeskItemByTypeAndGuid(res.className, res.value);
                        queryItem.attributes.Class = res.attributes.Class;
                        queryItem.attributes.ConfigurationItemType = res.attributes.ConfigurationItemType;
                        queryItem.attributes.CreateGroup           = res.attributes.CreateGroup;
                        queryItem.attributes.CreationUser          = res.attributes.CreationUser;
                        queryItem.attributes.CurrentAssignment     = res.attributes.CurrentAssignment;
                        queryItem.attributes.LastUpdateUser        = res.attributes.LastUpdateUser;
                        queryItem.attributes.LatestAssignmentGroup = res.attributes.LatestAssignmentGroup;
                        queryItem.attributes.Lifecycle             = res.attributes.Lifecycle;
                        queryItem.attributes.RaiseUser             = res.attributes.RaiseUser;
                        queryItem.attributes.Status              = res.attributes.Status;
                        queryItem.attributes.UpdateGroup         = res.attributes.UpdateGroup;
                        queryItem.attributes._CatalogueHierarchy = res.attributes._CatalogueHierarchy;
                        yield return(queryItem);
                    }
                }
            }
        }
Example #3
0
        private LanDeskItem ClosureSteps(LanDeskItem ldi)
        {
            var taskClosure = ToLanDesk(GetAndCloseChildTasks, ldi);

            if (!taskClosure.Success)
            {
                throw new Exception("Failed to properly close all of the child tasks during the closure process.");
            }
            var    parentClass = ldi.className;
            string function;
            string message;

            switch (parentClass)
            {
            case LanDeskItemType.Request:
                function = "AddProvisionConfirmation";
                message  =
                    "Development on this Request was completed. No additional code or modifications are necessary at this time. The code, if necessary, has been built to production web servers and should be available for the user to use at this time.";
                break;

            case LanDeskItemType.Incident:
                function = "Resolve";
                message  =
                    "The bug, error or omission has been corrected. The user should no longer experience the specific concern addressed in this Incident.";
                break;

            case LanDeskItemType.Problem:
                function = "AddDiagnosis";
                message  =
                    "Developers have determined that issue could be resolved by taking steps to modify, alter or otherwise impact the system affected.";
                break;

            default:
                return(new LanDeskItem {
                    Success = false
                });
            }
            ExecuteFunction(ldi, function, message);
            ldi.Success = true;
            if (parentClass != LanDeskItemType.Problem)
            {
                return(ldi);
            }
            ldi.Success = false;

            function = "AddSystemCause";
            message  =
                "The system which underlies this Problem contains one or more correctable errors. These errors are systemic and may be altered either on the server or via manipulation of the code controlling this system.";
            ExecuteFunction(ldi, function, message);

            function = "Resolve";
            message  =
                "The issue or concern at the heart of this Problem has been corrected. As a consequence, all users should be able to continue to use the system without continuing to experience the same error.";
            ExecuteFunction(ldi, function, message);

            ldi.Success = true;
            return(ldi);
        }
Example #4
0
        public LanDeskItem GetLatestAssignment(LanDeskItem lanDeskItem)
        {
            var ldToPass = new LanDeskItem
            {
                className = lanDeskItem.attributes.Class + "Management.Assignment",
                value     = lanDeskItem.attributes.LatestAssignment
            };

            return(ToLanDesk(OpenLanDeskItemSteps, ldToPass));
        }
Example #5
0
        private LanDeskItem FunctionSteps(HttpClient client, LanDeskItem lanDeskItem)
        {
            var functionResult =
                (dynamic)
                client.GetAsync(@"wd/object/invokeFunction.rails?class_name=" + lanDeskItem.className
                                + "&key=" + lanDeskItem.value +
                                "&function_name=" + lanDeskItem.Function).Result;

            return(JsonConvert.DeserializeObject <LanDeskItem>(functionResult.Content.ReadAsStringAsync().Result));
        }
Example #6
0
        public void ExecuteFunction(LanDeskItem lanDeskItem, string function, string message)
        {
            lanDeskItem.Function = function;
            var functionObject = ToLanDesk(FunctionSteps, lanDeskItem);
            var formContent    = GenerateForm(lanDeskItem, function, message, functionObject);
            var result         = ToLanDesk(SaveSteps, formContent);

            if (result != null && result.Success)
            {
                return;
            }
            throw new Exception("Function " + function + " failed not execute properly.");
        }
Example #7
0
        public LanDeskItem CreateSteps(HttpClient client, LanDeskItem lanDeskItem)
        {
            var queryPartUrl = string.Format("wd/object/create.rails?class_name={0}Management.{0}", lanDeskItem.className);
            var objectGet    = client.GetAsync(queryPartUrl).Result;

            if (!objectGet.IsSuccessStatusCode)
            {
                throw new Exception("LanDesk prevented creation of a new item of this type.");
            }
            var newObject = JsonConvert.DeserializeObject <LanDeskItem>(objectGet.Content.ReadAsStringAsync().Result);

            return(newObject);
        }
Example #8
0
        public LanDeskItem OpenLanDeskItemSteps(HttpClient client, LanDeskItem lanDeskItem)
        {
            var itemPartUrl = $"wd/object/open.rails?class_name={lanDeskItem.className}&key={lanDeskItem.value}";

            var itemGet = client.GetAsync(itemPartUrl).Result;

            if (!itemGet.IsSuccessStatusCode)
            {
                throw new Exception("No LanDesk items matched this query.");
            }

            return(JsonConvert.DeserializeObject <LanDeskItem>(itemGet.Content.ReadAsStringAsync().Result));
        }
Example #9
0
        public LanDeskItem ClassAndIdGetSteps(HttpClient client, LanDeskItem lanDeskItem)
        {
            var queryPartUrl =
                string.Format($"wd/query/list.rails?class_name={lanDeskItem.className}&cns=Id-c-0-&c0={lanDeskItem.name}");

            var queryGet = client.GetAsync(queryPartUrl).Result;

            if (!queryGet.IsSuccessStatusCode)
            {
                throw new Exception("No LanDesk items matched this query.");
            }

            return(JsonConvert.DeserializeObject <QueryResult>(queryGet.Content.ReadAsStringAsync().Result).objects.FirstOrDefault());
        }
Example #10
0
        private LanDeskItem GetAndCloseChildTasks(HttpClient client, LanDeskItem lanDeskItem)
        {
            var     parentClass = lanDeskItem.className;
            var     parentKey   = lanDeskItem.value;
            dynamic taskResult;

            switch (parentClass)
            {
            case LanDeskItemType.Request:
                taskResult =
                    client.GetAsync(
                        @"wd/query/list.rails?class_name=RequestManagement.Task&cns=Request-c-0&c0=" +
                        parentKey + "&attributes=Status%2CCreationDate%2CCreationUser").Result;
                break;

            case LanDeskItemType.Incident:
                taskResult =
                    client.GetAsync(
                        @"wd/query/list.rails?class_name=IncidentManagement.Task&cns=Incident-c-0&c0=" +
                        parentKey + "&attributes=Status%2CCreationDate%2CCreationUser").Result;
                break;

            case LanDeskItemType.Problem:
                taskResult =
                    client.GetAsync(
                        @"wd/query/list.rails?class_name=ProblemManagement.Task&cns=Problem-c-0&c0=" +
                        parentKey + "&attributes=Status%2CCreationDate%2CCreationUser").Result;
                break;

            default:
                return(new LanDeskItem {
                    Success = false
                });
            }
            var taskContent =
                JsonConvert.DeserializeObject <QueryResult>(taskResult.Content.ReadAsStringAsync().Result);

            foreach (var task in taskContent.objects)
            {
                if (task.attributes.Status == "Completed")
                {
                    continue;
                }
                ExecuteFunction((LanDeskItem)task, "Complete", "This task has been completed by the System Development department.");
            }
            lanDeskItem.Success = true;
            return(lanDeskItem);
        }
Example #11
0
 public bool SendClosure(LanDeskItem ldi)
 {
     if (ldi.attributes.Status == Constants.ClosedState ||
         ldi.attributes.Status == Constants.CancelledState ||
         ldi.attributes.Status == Constants.RejectedState ||
         ldi.attributes.Status == Constants.ResolvedState ||
         ldi.attributes.Status == Constants.AwaitingServiceDeskReviewState ||
         ldi.attributes.Status == "With Customer")
     {
         return(true);
     }
     try
     {
         return(!string.IsNullOrEmpty(ClosureSteps(ldi).value));
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #12
0
        private LanDeskItem LanDeskLogin(HttpClient client, LanDeskItem login)
        {
            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("Ecom_User_ID", _username),
                new KeyValuePair <string, string>("Ecom_User_Password", _password)
            });
            var post       = client.PostAsync("wd/Logon/Logon.rails", content);
            var postResult = post.Result;

            postResult.EnsureSuccessStatusCode();
            if (
                postResult.Headers.GetValues("X-RequestUrl")
                .Single()
                .Contains("Logon/IntegratedLogonFailed.rails"))
            {
                login.Success = false;
            }
            login.Success = true;
            return(login);
        }
Example #13
0
        private FormUrlEncodedContent GenerateForm(LanDeskItem lanDeskItem, string function, string message, LanDeskItem functionObject)
        {
            switch (function)
            {
            case "Create " + LanDeskItemType.Request:
                return(null);    // TODO: Construct item.

            case "Create " + LanDeskItemType.Incident:
                return(null);   // TODO: Construct item.

            case "Create " + LanDeskItemType.Problem:
                return(null);   // TODO: Construct item.
            }
            var functionContentArray = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("class_name", functionObject.className),
                new KeyValuePair <string, string>("key", functionObject.value),
                new KeyValuePair <string, string>("parent_class_name", lanDeskItem.className),
                new KeyValuePair <string, string>("parent_key", lanDeskItem.value),
                new KeyValuePair <string, string>("is_new", "True"),
                new KeyValuePair <string, string>("parent_function_name", function),
                new KeyValuePair <string, string>("CreationDate", functionObject.attributes.CreationDate),
                new KeyValuePair <string, string>("CreationUser", functionObject.attributes.CreationUser)
            };

            switch (function)
            {
            case "Authorise":
                functionContentArray.AddRange(new[]
                {
                    new KeyValuePair <string, string>("Text", message)
                });
                break;

            case "Resolve":
                switch (lanDeskItem.className)
                {
                case LanDeskItemType.Problem:
                    functionContentArray.AddRange(new[]
                    {
                        new KeyValuePair <string, string>("Category", "TODO SET ME"),            //TODO: Set the Problem Resolution Category for your LanDesk system.
                        new KeyValuePair <string, string>("Description", message)
                    });
                    break;

                case LanDeskItemType.Incident:
                    functionContentArray.AddRange(new[]
                    {
                        new KeyValuePair <string, string>("_NotifyOriginator", "True"),
                        new KeyValuePair <string, string>("_CopyCategory", "Development"),
                        new KeyValuePair <string, string>("Category", "TODO SET ME"),            //TODO: Set the Incident Resolution Category for your LanDesk system.
                        new KeyValuePair <string, string>("Description", message)
                    });
                    break;
                }

                break;

            case "AddSystemCause":
                functionContentArray.AddRange(new[]
                {
                    new KeyValuePair <string, string>("Description", message),
                    new KeyValuePair <string, string>("LastUpdate", functionObject.attributes.LastUpdate),
                    new KeyValuePair <string, string>("LastUpdateUser", functionObject.attributes.LastUpdateUser)
                });
                break;

            case "Complete":
                string completedTaskCategory;
                switch (lanDeskItem.className)
                {
                case LanDeskItemType.Request:
                    completedTaskCategory = "TODO SET ME";         // TODO: Add your category GUID for completed request status.
                    break;

                case LanDeskItemType.Incident:
                    completedTaskCategory = "TODO SET ME";         // TODO: Add your category GUID for completed incident status.
                    break;

                case LanDeskItemType.Problem:
                    completedTaskCategory = "TODO SET ME";         // TODO: Add your category GUID for completed problem status.
                    break;

                default:
                    throw new Exception("Unexpecxted item type submitted for function Complete. Please review method call and LanDeskItemType.");
                }
                functionContentArray.AddRange(new[]
                {
                    new KeyValuePair <string, string>("Category", completedTaskCategory),
                    new KeyValuePair <string, string>("Description",
                                                      "Task completed. Automatically closed by TFS Service.")
                });
                break;

            case "AddProvisionConfirmation":
                functionContentArray.AddRange(new[]
                {
                    new KeyValuePair <string, string>("_Details", message),
                    new KeyValuePair <string, string>("_CreateDate", functionObject.attributes._CreateDate),
                    new KeyValuePair <string, string>("_CreateUser", functionObject.attributes._CreateUser),
                    new KeyValuePair <string, string>("_UpdateUser", functionObject.attributes._UpdateUser)
                });
                functionContentArray.Remove(new KeyValuePair <string, string>("Creation Date", ""));
                functionContentArray.Remove(new KeyValuePair <string, string>("Creation User", ""));
                break;

            case "AddDiagnosis":
                functionContentArray.AddRange(new[]
                {
                    new KeyValuePair <string, string>("Text", message),
                    new KeyValuePair <string, string>("LastUpdate", functionObject.attributes.LastUpdate),
                    new KeyValuePair <string, string>("LastUpdateUser", functionObject.attributes.LastUpdateUser)
                });
                break;

            case "AddAssignment":
                // TODO Get guids for each. System.SupportGroup & System.Analyst
                var assignedGroupGuid = GetAssignedGroupIdByName(lanDeskItem.attributes._CurrentAssignedGroup) ?? "";
                var assigneeGuid      = GetAssigneeIdByName(lanDeskItem.attributes._CurrentAssignedAnalyst) ?? "";
                functionContentArray.AddRange(new[]
                {
                    new KeyValuePair <string, string>("Group", assignedGroupGuid),
                    new KeyValuePair <string, string>("User", assigneeGuid),
                    new KeyValuePair <string, string>("Description", message)
                });
                break;

            case "AddNote":
                functionContentArray.AddRange(new[]
                {
                    new KeyValuePair <string, string>("Text", message)
                });
                break;

            case "AddPrivateNote":
                functionContentArray.AddRange(new[]
                {
                    new KeyValuePair <string, string>("_Details", message),
                    new KeyValuePair <string, string>("_CreateDate", functionObject.attributes._CreateDate),
                    new KeyValuePair <string, string>("_CreateUser", functionObject.attributes._CreateUser)
                });
                functionContentArray.Remove(new KeyValuePair <string, string>("Creation Date", ""));
                functionContentArray.Remove(new KeyValuePair <string, string>("Creation User", ""));
                break;

            default:
                throw new Exception("Unexpected Function call.");
            }
            return(new FormUrlEncodedContent(functionContentArray));
        }