Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AutotaskApiTests"/> class.
 /// </summary>
 /// <param name="user">The username.</param>
 /// <param name="pass">The password.</param>
 public AutotaskApiTests(string user, string pass, string trackingId)
 {
     this.atwsServices = new ATWS {
         Url = this.webServiceBaseApiUrl
     };
     try
     {
         ATWSZoneInfo zoneInfo = this.atwsServices.getZoneInfo(user);
         if (zoneInfo.ErrorCode >= 0)
         {
             string urlZone = zoneInfo.URL;
             this.atwsServices = new ATWS {
                 Url = urlZone
             };
             NetworkCredential credentials = new NetworkCredential(user, pass);
             CredentialCache   cache       = new CredentialCache {
                 { new Uri(this.atwsServices.Url), "Basic", credentials }
             };
             this.atwsServices.Credentials = cache;
             this.atwsServices.AutotaskIntegrationsValue = new AutotaskIntegrations {
                 IntegrationCode = trackingId
             };
         }
         else
         {
             throw new Exception("Error with getZoneInfo()");
         }
     }
     catch (Exception exception)
     {
         throw new Exception("Error with getZoneInfo()- error: " + exception.Message);
     }
 }
        public static ArrayList GetListTables(string filter)
        {
            ArrayList list = new ArrayList();

            try
            {
                ATWS atws = new ATWS();
                atws.Credentials = new NetworkCredential("*****@*****.**", "12345");

                EntityInfo[] entityList = atws.getEntityInfo();

                foreach (EntityInfo entity in entityList)
                {
                    if (!filter.Equals(string.Empty))
                    {
                        if (entity.Name.ToUpper().Contains(filter.ToUpper()))
                        {
                            list.Add(entity.Name);
                        }
                    }
                    else
                    {
                        list.Add(entity.Name);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(list);
        }
        public static DataTable GetSchema(string tableName, string columnNameParameter)
        {
            CustomBoolean.Clear();

            DataTable table = GetDatatableSchema();

            ATWS atws = new ATWS();

            atws.Credentials = new NetworkCredential("*****@*****.**", "12345");
            ModelCreator.autotask.Field[] fields = atws.GetFieldInfo(tableName);

            foreach (ModelCreator.autotask.Field field in fields)
            {
                DataRow row = table.NewRow();
                row["Name"]         = field.Name;
                row["FieldName"]    = field.Name;
                row["Type"]         = GetType(field.Type);
                row["DbType"]       = GetType(field.Type);
                row["Length"]       = field.Length;
                row["Nullable"]     = field.IsRequired;
                row["Table"]        = tableName;
                row["Schema"]       = "";
                row["BusinessName"] = field.Name;
                row["Description"]  = field.Description;

                table.Rows.Add(row);
            }

            return(table);
        }
Beispiel #4
0
        /// <summary>
        /// Creates the ATWS client for the API.
        /// </summary>
        /// <returns>The ATWS client.</returns>
        private ATWS GetClient()
        {
            string username = ConfigurationManager.AppSettings["Username"];
            string password = ConfigurationManager.AppSettings["Password"];
            ATWS   service  = new ATWS {
                Url = ConfigurationManager.AppSettings["BaseURL"]
            };

            try
            {
                ATWSZoneInfo zoneInfo = service.getZoneInfo(username);
                string       urlZone  = zoneInfo.URL;
                service = new ATWS {
                    Url = urlZone
                };
                NetworkCredential credentials = new NetworkCredential(username, password);
                CredentialCache   cache       = new CredentialCache {
                    { new Uri(service.Url), "Basic", credentials }
                };
                service.Credentials = cache;
            }
            catch (Exception exception)
            {
                throw new Exception("Error creating web service: " + exception.Message);
            }

            return(service);
        }
Beispiel #5
0
        /// <summary>
        /// Gets the ticket using the ticket id.
        /// </summary>
        /// <param name="client">The API client.</param>
        /// <param name="ticketId">The id of the ticket to get.</param>
        /// <returns>A ticket entity or null if no results were returned.</returns>
        private Ticket GetTicket(ATWS client, string ticketId)
        {
            StringBuilder xml = new StringBuilder();

            xml.AppendLine("<queryxml>");
            xml.AppendLine("<entity>Ticket</entity>");
            xml.AppendLine("<query>");
            xml.Append("<field>id<expression op=\"equals\">").Append(ticketId).AppendLine("</expression></field>");
            xml.AppendLine("</query>");
            xml.AppendLine("</queryxml>");
            ATWSResponse response = client.query(xml.ToString());

            if (response.ReturnCode == -1)
            {
                StringBuilder message = new StringBuilder();
                foreach (ATWSError atwsError in response.Errors)
                {
                    message.Append(atwsError.Message).Append(Environment.NewLine);
                }

                throw new Exception(message.ToString());
            }

            if (response.EntityResults.Length > 0)
            {
                return(response.EntityResults[0] as Ticket);
            }

            return(null);
        }
Beispiel #6
0
 /// <summary>
 /// The Page_Load method.
 /// </summary>
 /// <param name="sender">The Sender.</param>
 /// <param name="e">The EventArgs.</param>
 protected void Page_Load(object sender, EventArgs e)
 {
     if (client == null)
     {
         client = GetClient();
     }
 }
Beispiel #7
0
        public static ArrayList GetEmails()
        {
            if (client == null)
            {
                client = GetClient();
            }

            ArrayList emails = (ArrayList)HttpContext.Current.Session["Emails"];

            if (emails != null)
            {
                return(emails);
            }

            emails = new ArrayList();
            List <Contact> contacts = GetContacts();

            foreach (Contact contact in contacts)
            {
                string email = contact.EMailAddress.ToString();
                if (!emails.Contains(email))
                {
                    emails.Add(email);
                }
            }

            HttpContext.Current.Session["Emails"]   = emails;
            HttpContext.Current.Session["Contacts"] = contacts;
            return(emails);
        }
Beispiel #8
0
        /// <summary>
        /// The Page_Load Method.
        /// </summary>
        /// <param name="sender">The Sender.</param>
        /// <param name="e">The EventArgs.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            string ticketId = this.Request.Params["TicketID"];

            if (string.IsNullOrEmpty(ticketId))
            {
                return;
            }

            string rating = this.Request.Params["Rating"];

            ATWS   client = this.GetClient();
            Ticket ticket = this.GetTicket(client, ticketId);

            if (ticket == null)
            {
                return;
            }

            // If the ticket has no UDF values populated the user defined field array will be empty.
            if (ticket.UserDefinedFields.Length == 0)
            {
                UserDefinedField responseRating = new UserDefinedField {
                    Name = "Emoticon Response", Value = rating
                };
                UserDefinedField responseDate = new UserDefinedField {
                    Name = "Emoticon Response Date", Value = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)
                };
                ticket.UserDefinedFields    = new UserDefinedField[2];
                ticket.UserDefinedFields[0] = responseRating;
                ticket.UserDefinedFields[1] = responseDate;
            }
            else
            {
                UserDefinedField responseRating = ticket.UserDefinedFields.First(udf => udf.Name.Equals("Emoticon Response"));
                responseRating.Value = rating;
                UserDefinedField responseDate = ticket.UserDefinedFields.First(udf => udf.Name.Equals("Emoticon Response Date"));
                responseDate.Value = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);
            }

            ATWSResponse response = client.update(new Entity[] { ticket });

            if (response.ReturnCode != -1)
            {
                return;
            }

            StringBuilder message = new StringBuilder();

            foreach (ATWSError atwsError in response.Errors)
            {
                message.Append(atwsError.Message).Append(Environment.NewLine);
            }

            throw new Exception(message.ToString());
        }