예제 #1
0
        public static void Start(string installDirectory, string programStatePath,
                                 string GUIconfigPath, string DDTOpath)
        {
            /*
             * This program listens for a 'call to action bool'
             *  - the second character in a string from the
             *  - run state config file for this MS
             * On TRUE it reads the DDTO, which the GUI MS
             * will have sent the current set of expressions to
             * evaluate, then set the GUI's call to action state
             * to false - meaning it cannot write to the DDTO,
             * though it will store the command and do it asap,
             * then this daemon will read the DDTO and implement
             * the expressions in it, after it resets its own
             * and the GUI's call to action, turning itself off
             * and the GUI's write ability on
             */
            RunState programState;

            Console.WriteLine(" -- Daemon - Start --");
            try {
                do
                {
                    programState = RunState.GetProgramState(programStatePath);

                    if (programState.GetActionState())
                    {
                        CloseGUIsemaphore(GUIconfigPath);

                        var PROG_ID = "SldWorks.Application.24";

                        var swType = Type.GetTypeFromProgID(PROG_ID);

                        ValidateSWtype(swType);

                        swApp = (ISldWorks)Activator.CreateInstance(swType);

                        CreateSWAppInstance(swApp);

                        var blobName = programState.GetBlobName();

                        var blobPath = installDirectory + "blob\\" + blobName;

                        DocumentSpecification documentSpecification =
                            SWDocSpecification.GetDocumentSpecification(swApp, blobPath);

                        if (documentSpecification == null)
                        {
                            Console.WriteLine("Could not Get Document Specification for - " +
                                              blobPath);

                            return;
                        }

                        Console.WriteLine(" - Obtained Document Specification for - " + blobPath);

                        var model = swApp.OpenDoc7(
                            documentSpecification);

                        if (model == null)
                        {
                            Console.WriteLine(" - ERROR - Could not Open Document - " + blobPath);

                            return;
                        }

                        Console.WriteLine(" - Opened SolidWorks Document - " + blobPath);

                        EquationMgr equationManager = model.GetEquationMgr();

                        if (equationManager == null)
                        {
                            Console.WriteLine("Could Not Get Equation Manager Instance");

                            Console.WriteLine(" - Closing All Open SolidWorks Documents");
                            swApp.CloseAllDocuments(true);

                            return;
                        }

                        Console.WriteLine(" - Created Equation Manager Instance");

                        var rawBlempString = Blemp.LoadDDTO(DDTOpath);

                        var writeSuccess = false;
                        var timeOut      = 5;

                        if (rawBlempString != null)
                        {
                            var equationSegments = Blemp.GetDDTOequationSegments(rawBlempString);

                            if (equationSegments != null)
                            {
                                Console.WriteLine(" - Valid Equations Found - Processing");

                                try
                                {
                                    for (var i = 0; i < equationSegments.Length; ++i)
                                    {
                                        SWEquation.AddEquation(
                                            equationManager,
                                            equationSegments[i]
                                            );

                                        SWEquation.Build(
                                            model
                                            );

                                        SWEquation.DeleteEquation(
                                            equationManager,
                                            0);
                                    }
                                }
                                catch (ArgumentOutOfRangeException exception)
                                {
                                    Console.WriteLine(exception);
                                }
                            }
                            else
                            {
                                Console.WriteLine(" - WARNING - No Valid Equations for Processing Found");
                            }
                        }
                        else
                        {
                            Console.WriteLine("No Equations Found in DDTO");
                        }

                        do
                        {
                            Console.WriteLine(" - Closing Call to Action Semaphore");

                            writeSuccess = FileWrite.WriteStringToFileFalseOnFail(
                                programStatePath, "011!"
                                );

                            FileWrite.WriteStringToFileFalseOnFail(DDTOpath, "");

                            Thread.Sleep(300);
                        } while (!writeSuccess && timeOut-- > 0);

                        if (timeOut > 0)
                        {
                            Console.WriteLine(" - Call to Action Semaphore - Successfuly Closed");
                        }
                        else
                        {
                            Console.WriteLine(" - ERROR - Could Not Write Call to Action Close Command");

                            Console.WriteLine(" - Exiting Daemon -");

                            Console.WriteLine(" -- Daemon - Exit --");

                            return;
                        }

                        timeOut = 5;

                        do
                        {
                            Console.WriteLine(" - Opening GUI Call to Action Semaphore");

                            writeSuccess = FileWrite.WriteStringToFileFalseOnFail(
                                GUIconfigPath, "00"
                                );

                            Thread.Sleep(300);
                        } while (!writeSuccess && timeOut-- > 0);
                    }

                    if (programState.GetCloseBlob())
                    {
                        CloseGUIsemaphore(GUIconfigPath);

                        if (swApp != null)
                        {
                            swApp.CloseAllDocuments(true);
                        }

                        FileWrite.WriteStringToFileFalseOnFail(programStatePath, "011!");

                        Console.WriteLine(" - Opening GUI Call to Action Semaphore");

                        FileWrite.WriteStringToFileFalseOnFail(
                            GUIconfigPath, "00");
                    }

                    Thread.Sleep(300);
                } while (programState.GetRunState());
            } catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            if (swApp != null)
            {
                swApp.CloseAllDocuments(true);
            }

            Console.WriteLine(" -- Daemon - Exit --");
        }
예제 #2
0
        public static void Start()
        {
            var blempDDOpath     = "C:\\Users\\bolinger\\Desktop\\test install\\programFiles\\blemp\\DDO.blemp";
            var programStatePath = "C:\\Users\\bolinger\\Desktop\\test install\\programFiles\\config\\SWmicroservice.config";
            var programState     = "0";

            string current = null;
            string compare = null;

            logger.Debug("\n Microservice Daemon Started");

            do
            {
                var rawBlempString = Blemp.LoadDDO(blempDDOpath);

                if (rawBlempString == null)
                {
                    logger.Error("\n ERROR: Unable to load Blemp DDO");
                    return;
                }

                if (string.Compare(rawBlempString, "") != 0)
                {
                    logger.Debug("\n - Raw blemp data - " + rawBlempString +
                                 "\n - Press Any Key to Continue...");
                }

                // Console.Read();

                string blempString = "";

                try
                {
                    blempString = File.ReadAllText(blempDDOpath);
                } catch (IOException exception)
                {
                    logger.Error(exception, "Error Could Not Read DDO.blemp");
                }

                if (string.Compare(
                        blempString == null ? "" : blempString,
                        "") != 0)
                {
                    Blemp.PopulateDDO(rawBlempString);

                    logger.Debug(" - DDO Count - " + Config.DDO.Count +
                                 "\n - Press Any Key to Continue...");

                    // Console.Read();
                    try
                    {
                        compare = Config.DDO[1];

                        logger.Debug(" - compare & DDO[1] - " + compare
                                     + "   " + Config.DDO[1] +
                                     "\n - Press Any Key to Continue...");

                        // Console.Read();

                        if (string.Compare(current, compare) != 0)
                        {
                            current = compare;

                            string equation = Config.DDO[0] + Config.DDO[1] +
                                              Config.DDO[2];

                            logger.Debug(" - Equation to SW - " + equation +
                                         "\n - Press Any Key to Continue...");

                            //Console.Read();

                            SWEquation.AddEquation(
                                Config.equationManager,
                                equation
                                );

                            SWEquation.Build(
                                Config.model
                                );

                            SWEquation.DeleteEquation(
                                Config.equationManager
                                , 0);
                        }
                    } catch (ArgumentOutOfRangeException) { }
                }

                Thread.Sleep(300);

                programState = GetProgramState(programStatePath);

                if (programState == null)
                {
                    logger.Error("\n ERROR: Could not read program state");

                    return;
                }
            } while (string.Equals(programState, "0"));

            logger.Debug("\n Microservice Daemon Exiting");
        }