Ejemplo n.º 1
0
        /// <summary>
        /// Updates an existing activity script
        /// </summary>
        /// <param name="activityId">Unique name identifying the activity to be updated. Activity with this name must already exist.</param>
        /// <param name="script">Script to replace the existing one associated with the activity</param>
        /// <returns>true if activity was updated, false otherwise</returns>
        public static bool UpdateActivity(String activityId, String script)
        {
            if (String.IsNullOrEmpty(activityId) || String.IsNullOrEmpty(script))
            {
                return(false);
            }

            // Identify the result file in the script.
            // The result file name can be any name of your choice, AutoCAD IO does not have a restriction on that.
            // But just to make the code generic and to have it identify the result file automatically from the script,
            // we look for anything that sounds like result.pdf, Result.dwf, RESULT.DWG etc.
            String resultLocalFileName = String.Empty;

            foreach (Match m in Regex.Matches(script, "(?i)result.[a-z][a-z][a-z]"))
            {
                resultLocalFileName = m.Value;
            }

            if (String.IsNullOrEmpty(resultLocalFileName))
            {// Script did not have file name like Result.pdf, Result.dwg ....
                Console.WriteLine(String.Format("Could not identify the result output file in the provided script ! Please use result.* as the output of the script."));
                return(false);
            }

            bool activityUpdated = false;

            try
            {
                foreach (AIO.ACES.Models.Activity act1 in container.Activities)
                {
                    if (activityId.Equals(act1.Id))
                    {
                        var ins = new AIO.ACES.Models.Instruction();
                        ins.Script       = script;
                        act1.Instruction = ins;
                        container.UpdateObject(act1);
                        container.SaveChanges();
                        activityUpdated = true;
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(activityUpdated);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the activity name and script associated with the activities
        /// </summary>
        /// <returns>Key Value pair of the activity names and script associated with each activity</returns>
        public static Dictionary <String, String> GetActivityDetails()
        {
            Dictionary <String, String> activityDetails = new Dictionary <string, string>();

            try
            {
                foreach (AIO.ACES.Models.Activity act in container.Activities)
                {
                    String activityId = act.Id;
                    AIO.ACES.Models.Instruction activityInstruction = act.Instruction;
                    activityDetails.Add(String.Format("{0}", activityId), act.Instruction.Script);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(activityDetails);
        }
        /// <summary>
        /// Updates an existing activity script
        /// </summary>
        /// <param name="activityId">Unique name identifying the activity to be updated. Activity with this name must already exist.</param>
        /// <param name="script">Script to replace the existing one associated with the activity</param>
        /// <returns>true if activity was updated, false otherwise</returns>
        public static bool UpdateActivity(String activityId, String script)
        {
            if (String.IsNullOrEmpty(activityId) || String.IsNullOrEmpty(script))
                return false;

            // Identify the result file in the script.
            // The result file name can be any name of your choice, AutoCAD IO does not have a restriction on that.
            // But just to make the code generic and to have it identify the result file automatically from the script,
            // we look for anything that sounds like result.pdf, Result.dwf, RESULT.DWG etc.
            String resultLocalFileName = String.Empty;
            foreach (Match m in Regex.Matches(script, "(?i)result.[a-z][a-z][a-z]"))
            {
                resultLocalFileName = m.Value;
            }

            if (String.IsNullOrEmpty(resultLocalFileName))
            {// Script did not have file name like Result.pdf, Result.dwg ....
                Console.WriteLine(String.Format("Could not identify the result output file in the provided script ! Please use result.* as the output of the script."));
                return false;
            }

            bool activityUpdated = false;

            try
            {
                foreach (AIO.ACES.Models.Activity act1 in container.Activities)
                {
                    if (activityId.Equals(act1.Id))
                    {
                        var ins = new AIO.ACES.Models.Instruction();
                        ins.Script = script;
                        act1.Instruction = ins;
                        container.UpdateObject(act1);
                        container.SaveChanges(); 
                        activityUpdated = true;
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return activityUpdated;
        }