コード例 #1
0
        public async Task <IActionResult> CreateActivity([FromBody] JObject activitySpecs)
        {
            // basic input validation
            string zipFileName = activitySpecs["zipFileName"].Value <string>();
            string engineName  = activitySpecs["engine"].Value <string>();

            // define Activities API
            dynamic oauth = await OAuthController.GetInternalAsync();

            ActivitiesApi activitiesApi = new ActivitiesApi();

            activitiesApi.Configuration.AccessToken = oauth.access_token;

            // standard name for this sample
            string appBundleName = zipFileName + "AppBundle";
            string activityName  = zipFileName + "Activity";

            //
            PageString activities = await activitiesApi.ActivitiesGetItemsAsync();

            string qualifiedActivityId = string.Format("{0}.{1}+{2}", NickName, activityName, Alias);

            if (!activities.Data.Contains(qualifiedActivityId))
            {
                // define the activity
                // ToDo: parametrize for different engines...
                string         commandLine  = string.Format(@"$(engine.path)\\{0} /i $(args[inputFile].path) /al $(appbundles[{1}].path)", Executable(engineName), appBundleName);
                ModelParameter inputFile    = new ModelParameter(false, false, ModelParameter.VerbEnum.Get, "input file", true, "$(inputFile)");
                ModelParameter inputJson    = new ModelParameter(false, false, ModelParameter.VerbEnum.Get, "input json", false, "params.json");
                ModelParameter outputFile   = new ModelParameter(false, false, ModelParameter.VerbEnum.Put, "output file", true, "outputFile.rvt");
                Activity       activitySpec = new Activity(
                    new List <string>()
                {
                    commandLine
                },
                    new Dictionary <string, ModelParameter>()
                {
                    { "inputFile", inputFile },
                    { "inputJson", inputJson },
                    { "outputFile", outputFile }
                },
                    engineName, new List <string>()
                {
                    string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias)
                }, null,
                    string.Format("Description for {0}", activityName), null, activityName);
                Activity newActivity = await activitiesApi.ActivitiesCreateItemAsync(activitySpec);

                // specify the alias for this Activity
                Alias aliasSpec = new Alias(1, null, Alias);
                Alias newAlias  = await activitiesApi.ActivitiesCreateAliasAsync(activityName, aliasSpec);

                return(Ok(new { Activity = qualifiedActivityId }));
            }

            // as this activity points to a AppBundle "dev" alias (which points to the last version of the bundle),
            // there is no need to update it (for this sample), but this may be extended for different contexts
            return(Ok(new { Activity = "Activity already defined" }));
        }
コード例 #2
0
        static private AbstrPageEl ReadLikePageString(XmlNode nd_el)
        {
            PageEl out_pageEl = new PageEl();
            string pos_x = "0", pos_y = "0",
                   clr_hex = "0x", sz = "0", dt_str = "";

            foreach (XmlNode nd_string_par in nd_el)
            {
                switch (nd_string_par.Name)
                {
                case (XMLDefines.XMLStringTag.Position):

                    pos_x = nd_string_par.Attributes.GetNamedItem(
                        XMLDefines.XMLStringAttr.PosX).Value;
                    pos_y = nd_string_par.Attributes.GetNamedItem(
                        XMLDefines.XMLStringAttr.PosY).Value;
                    break;

                case (XMLDefines.XMLStringTag.Color):
                    clr_hex = nd_string_par.Attributes.GetNamedItem(
                        XMLDefines.XMLStringAttr.ColorValue).Value;
                    break;

                case (XMLDefines.XMLStringTag.Size):
                    sz = nd_string_par.Attributes.GetNamedItem(
                        XMLDefines.XMLStringAttr.SizeValue).Value;
                    break;

                case (XMLDefines.XMLStringTag.Data):
                    dt_str = nd_string_par.Attributes.GetNamedItem(
                        XMLDefines.XMLStringAttr.Data).Value;
                    break;
                }
            }

            try
            {
                Byte   b_pos_x, b_pos_y, b_sz;
                AColor color;

                b_pos_x = Convert.ToByte(pos_x);
                b_pos_y = Convert.ToByte(pos_y);
                b_sz    = Convert.ToByte(sz);

                color      = new AColor(clr_hex);
                out_pageEl = new PageString(b_pos_x, b_pos_y, color, b_sz, dt_str);
            }
            catch (Exception e)
            {
            }
            return(out_pageEl);
        }
コード例 #3
0
        public async Task <List <string> > GetAvailableEngines()
        {
            dynamic oauth = await OAuthController.GetInternalAsync();

            // define Engines API
            EnginesApi enginesApi = new EnginesApi();

            enginesApi.Configuration.AccessToken = oauth.access_token;
            PageString engines = await enginesApi.EnginesGetItemsAsync();

            engines.Data.Sort();

            return(engines.Data); // return list of engines
        }
コード例 #4
0
        public async Task <List <string> > GetDefinedActivities()
        {
            dynamic oauth = await OAuthController.GetInternalAsync();

            // define Activities API
            ActivitiesApi activitiesApi = new ActivitiesApi();

            activitiesApi.Configuration.AccessToken = oauth.access_token;;

            // filter list of
            PageString activities = await activitiesApi.ActivitiesGetItemsAsync();

            List <string> definedActivities = new List <string>();

            foreach (string activity in activities.Data)
            {
                if (activity.StartsWith(NickName) && activity.IndexOf("$LATEST") == -1)
                {
                    definedActivities.Add(activity.Replace(NickName + ".", String.Empty));
                }
            }

            return(definedActivities);
        }
コード例 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var ps = new PageString();



            /*可选参数*/

            ps.SetIsEnglish(true);  // 是否是英文       (默认:false)
            ps.SetIsShowText(true); //是否显示分页文字 (默认:true)
            //ps.SetTextFormat                       (默认值:《span class=\"pagetext\"》《strong》总共《/strong》:{0} 条 《strong》当前《/strong》:{1}/{2}《/span》)
            //ps.SetPageIndexName  Request["pageIndex"](默认值:"pageIndex")
            ps.SetIsAjax(false);//                    (默认值:"false")

            /*函数参数*/
            int total     = 10000;
            int pageSize  = 10;
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);

            var page = ps.ToPageString(total, pageSize, pageIndex, "/UI/PageStringTest.aspx?");

            //获取 page html 输出
            Response.Write(page);
        }
コード例 #6
0
        public async Task <IActionResult> CreateAppBundle([FromBody] JObject appBundleSpecs)
        {
            // basic input validation
            string zipFileName = appBundleSpecs["zipFileName"].Value <string>();
            string engineName  = appBundleSpecs["engine"].Value <string>();

            // standard name for this sample
            string appBundleName = zipFileName + "AppBundle";

            // check if ZIP with bundle is here
            string packageZipPath = Path.Combine(LocalBundlesFolder, zipFileName + ".zip");

            if (!System.IO.File.Exists(packageZipPath))
            {
                throw new Exception("Appbundle not found at " + packageZipPath);
            }

            // define Activities API
            dynamic oauth = await OAuthController.GetInternalAsync();

            AppBundlesApi appBundlesApi = new AppBundlesApi();

            appBundlesApi.Configuration.AccessToken = oauth.access_token;

            // get defined app bundles
            PageString appBundles = await appBundlesApi.AppBundlesGetItemsAsync();

            // check if app bundle is already define
            dynamic newAppVersion;
            string  qualifiedAppBundleId = string.Format("{0}.{1}+{2}", NickName, appBundleName, Alias);

            if (!appBundles.Data.Contains(qualifiedAppBundleId))
            {
                // create an appbundle (version 1)
                AppBundle appBundleSpec = new AppBundle(appBundleName, null, engineName, null, null, string.Format("Description for {0}", appBundleName), null, appBundleName);
                newAppVersion = await appBundlesApi.AppBundlesCreateItemAsync(appBundleSpec);

                if (newAppVersion == null)
                {
                    throw new Exception("Cannot create new app");
                }

                // create alias pointing to v1
                Alias aliasSpec = new Alias(1, null, Alias);
                Alias newAlias  = await appBundlesApi.AppBundlesCreateAliasAsync(appBundleName, aliasSpec);
            }
            else
            {
                // create new version
                AppBundle appBundleSpec = new AppBundle(null, null, engineName, null, null, appBundleName, null, null);
                newAppVersion = await appBundlesApi.AppBundlesCreateItemVersionAsync(appBundleName, appBundleSpec);

                if (newAppVersion == null)
                {
                    throw new Exception("Cannot create new version");
                }

                // update alias pointing to v+1
                Alias aliasSpec = new Alias(newAppVersion.Version, null, null);
                Alias newAlias  = await appBundlesApi.AppBundlesModifyAliasAsync(appBundleName, Alias, aliasSpec);
            }

            // upload the zip with .bundle
            RestClient  uploadClient = new RestClient(newAppVersion.UploadParameters.EndpointURL);
            RestRequest request      = new RestRequest(string.Empty, Method.POST);

            request.AlwaysMultipartFormData = true;
            foreach (KeyValuePair <string, object> x in newAppVersion.UploadParameters.FormData)
            {
                request.AddParameter(x.Key, x.Value);
            }
            request.AddFile("file", packageZipPath);
            request.AddHeader("Cache-Control", "no-cache");
            await uploadClient.ExecuteTaskAsync(request);

            return(Ok(new { AppBundle = qualifiedAppBundleId, Version = newAppVersion.Version }));
        }
コード例 #7
0
        /// <summary>
        /// 获取分页html
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public HtmlString GetPageString(int pageIndex, int pageSize, int pageCount)
        {
            PageString ps = new PageString();

            return(new HtmlString(ps.ToPageString(pageCount, pageSize, pageIndex, "/List/Index?")));
        }
コード例 #8
0
        public override AbstrPageEl CompileElement()
        {
            string dt  = "";
            AColor clr = AColors.WHITE;
            int    px  = 0;
            int    py  = 0;
            int    sz  = 0;

            foreach (UIElement ch in Container.Children)
            {
                switch (ch.Uid)
                {
                case "tbT":
                    dt = ((TextBox)ch).Text;
                    break;

                case "tbS":
                    if (int.TryParse(((TextBox)ch).Text, out sz))
                    {
                        sz = (sz & byte.MaxValue);
                    }
                    else
                    {
                        sz = 0;
                    }
                    break;

                case "tbY":
                    if (int.TryParse(((TextBox)ch).Text, out py))
                    {
                        py = (py & byte.MaxValue);
                    }
                    else
                    {
                        py = 0;
                    }
                    break;

                case "tbX":
                    if (int.TryParse(((TextBox)ch).Text, out px))
                    {
                        px = (px & byte.MaxValue);
                    }
                    else
                    {
                        px = 0;
                    }
                    break;

                case "clrBox":
                    try
                    { clr = new AColor(((UIAcolorBox)ch).GeBoxColor()); }
                    catch
                    { }
                    break;
                }
            }
            AbstrPageEl p_out;

            p_out = new PageString(
                (byte)px, (byte)py,
                clr,
                (byte)sz,
                dt);

            return(p_out);
        }
コード例 #9
0
        public UIPageString(AbstrPageEl pEl)
            : base(60)
        {
            PageString ps = (PageString)pEl;

            // Интерфейс для настройки позиции
            Label   lbl_pos = new Label();
            TextBox tbX     = new TextBox();
            TextBox tbY     = new TextBox();

            lbl_pos.Content = "Позиция";
            tbX.Text        = ps.X.ToString();
            tbY.Text        = ps.Y.ToString();

            tbX.MaxLength = 3;
            tbY.MaxLength = 3;

            tbX.Width = 25;
            tbY.Width = 25;

            tbX.Height = 23;
            tbY.Height = 23;

            tbX.TextAlignment = TextAlignment.Center;
            tbY.TextAlignment = TextAlignment.Center;

            //

            // Цвет
            UIAcolorBox clrBox = new UIAcolorBox(
                ps.TextColor.GetColor());

            // Размер
            Label   lbl_size = new Label();
            TextBox tbS      = new TextBox();

            lbl_size.Content = "Размер";
            tbS.Text         = ps.Size.ToString();

            tbS.Width  = 25;
            tbS.Height = 23;
            //

            // Текст
            TextBox tbT = new TextBox();

            tbT.Height = 23;
            tbT.Text   = ps.Data;

            DockPanel.SetDock(tbT, Dock.Bottom);
            //

            Container.Children.Add(tbT);

            Container.Children.Add(lbl_pos);
            Container.Children.Add(tbX);
            Container.Children.Add(
                UIGenerateHelping.NewGridSplitter(10, Container.Background));
            Container.Children.Add(tbY);

            Container.Children.Add(
                UIGenerateHelping.NewGridSplitter(10, Container.Background));

            Container.Children.Add(clrBox);

            Container.Children.Add(
                UIGenerateHelping.NewGridSplitter(10, Container.Background));

            Container.Children.Add(lbl_size);
            Container.Children.Add(tbS);


            clrBox.Uid = "clrBox";
            tbX.Uid    = "tbX";
            tbY.Uid    = "tbY";
            tbS.Uid    = "tbS";
            tbT.Uid    = "tbT";
        }
コード例 #10
0
        static private XmlElement XmlElFromPageString(AbstrPageEl pEl, XmlDocument xdd)
        {
            PageString ps = (PageString)pEl;

            // Описание элемента
            var ndPageEl = xdd.CreateElement(
                (XMLDefines.XMLTag.PageEl).ToString());

            var attrTypeEl = xdd.CreateAttribute(
                XMLDefines.XMLStringAttr.TypeEl.ToString());

            attrTypeEl.Value = ((int)ps.GetTypeEl()).ToString();

            ndPageEl.Attributes.Append(attrTypeEl);

            // Позиция
            var ndPos = xdd.CreateElement(
                XMLDefines.XMLStringTag.Position.ToString());

            var attrPosX = xdd.CreateAttribute(
                XMLDefines.XMLStringAttr.PosX.ToString());
            var attrPosY = xdd.CreateAttribute(
                XMLDefines.XMLStringAttr.PosY.ToString());

            attrPosX.Value = ps.X.ToString();
            attrPosY.Value = ps.Y.ToString();

            ndPos.Attributes.Append(attrPosX);
            ndPos.Attributes.Append(attrPosY);

            // Цвет
            var ndClr = xdd.CreateElement(
                XMLDefines.XMLStringTag.Color.ToString());

            var attrClr = xdd.CreateAttribute(
                XMLDefines.XMLStringAttr.ColorValue.ToString());

            attrClr.Value = ps.TextColor.ToHex();

            ndClr.Attributes.Append(attrClr);

            // Размер
            var ndSz = xdd.CreateElement(
                XMLDefines.XMLStringTag.Size.ToString());

            var attrSz = xdd.CreateAttribute(
                XMLDefines.XMLStringAttr.SizeValue.ToString());

            attrSz.Value = ps.Size.ToString();

            ndSz.Attributes.Append(attrSz);

            // Текст
            var ndDt = xdd.CreateElement(
                XMLDefines.XMLStringTag.Data.ToString());

            var attrDt = xdd.CreateAttribute(
                XMLDefines.XMLStringAttr.Data.ToString());

            attrDt.Value = ps.Data;

            ndDt.Attributes.Append(attrDt);


            //
            ndPageEl.AppendChild(ndPos);
            ndPageEl.AppendChild(ndClr);
            ndPageEl.AppendChild(ndSz);
            ndPageEl.AppendChild(ndDt);

            return(ndPageEl);
        }
コード例 #11
0
        /// <summary>
        /// Creates Activity
        /// </summary>
        /// <returns>True if successful</returns>
        public static async Task <dynamic> CreateActivity()
        {
            Bearer bearer   = (await Get2LeggedTokenAsync(new Scope[] { Scope.CodeAll })).ToObject <Bearer>();
            string nickName = ConsumerKey;

            AppBundlesApi appBundlesApi = new AppBundlesApi();

            appBundlesApi.Configuration.AccessToken = bearer.AccessToken;
            PageString appBundles = await appBundlesApi.AppBundlesGetItemsAsync();

            string appBundleID = string.Format("{0}.{1}+{2}", nickName, APPNAME, ALIAS);

            if (!appBundles.Data.Contains(appBundleID))
            {
                if (!System.IO.File.Exists(LocalAppPackageZip))
                {
                    return(new Output(Output.StatusEnum.Error, "Bundle not found at " + LocalAppPackageZip));
                }
                // create new bundle
                AppBundle appBundleSpec = new AppBundle(APPNAME, null, EngineName, null, null, APPNAME, null, APPNAME);
                AppBundle newApp        = await appBundlesApi.AppBundlesCreateItemAsync(appBundleSpec);

                if (newApp == null)
                {
                    return(new Output(Output.StatusEnum.Error, "Cannot create new app"));
                }
                // create alias
                Alias aliasSpec = new Alias(1, null, ALIAS);
                Alias newAlias  = await appBundlesApi.AppBundlesCreateAliasAsync(APPNAME, aliasSpec);

                // upload the zip bundle
                RestClient  uploadClient = new RestClient(newApp.UploadParameters.EndpointURL);
                RestRequest request      = new RestRequest(string.Empty, Method.POST);
                request.AlwaysMultipartFormData = true;
                foreach (KeyValuePair <string, object> x in newApp.UploadParameters.FormData)
                {
                    request.AddParameter(x.Key, x.Value);
                }
                request.AddFile("file", LocalAppPackageZip);
                request.AddHeader("Cache-Control", "no-cache");
                var res = await uploadClient.ExecuteTaskAsync(request);
            }
            ActivitiesApi activitiesApi = new ActivitiesApi();

            activitiesApi.Configuration.AccessToken = bearer.AccessToken;
            PageString activities = await activitiesApi.ActivitiesGetItemsAsync();

            string activityID = string.Format("{0}.{1}+{2}", nickName, ACTIVITY_NAME, ALIAS);

            if (!activities.Data.Contains(activityID))
            {
                // create activity
                string         commandLine  = string.Format(@"$(engine.path)\\inventorcoreconsole.exe /i $(args[InputIPT].path) /al $(appbundles[{0}].path) $(args[InputParams].path)", APPNAME);
                ModelParameter iptFile      = new ModelParameter(false, false, ModelParameter.VerbEnum.Get, "Input Ipt File", true, inputFileName);
                ModelParameter result       = new ModelParameter(false, false, ModelParameter.VerbEnum.Put, "Resulting Ipt File", true, outputFileName);
                ModelParameter inputParams  = new ModelParameter(false, false, ModelParameter.VerbEnum.Get, "Input params", false, "params.json");
                Activity       activitySpec = new Activity(
                    new List <string> {
                    commandLine
                },
                    new Dictionary <string, ModelParameter>()
                {
                    { "InputIPT", iptFile },
                    { "InputParams", inputParams },
                    { "ResultIPT", result },
                },
                    EngineName,
                    new List <string>()
                {
                    string.Format("{0}.{1}+{2}", nickName, APPNAME, ALIAS)
                },
                    null,
                    ACTIVITY_NAME,
                    null,
                    ACTIVITY_NAME
                    );
                Activity newActivity = await activitiesApi.ActivitiesCreateItemAsync(activitySpec);

                Alias aliasSpec = new Alias(1, null, ALIAS);
                Alias newAlias  = await activitiesApi.ActivitiesCreateAliasAsync(ACTIVITY_NAME, aliasSpec);
            }
            return(new Output(Output.StatusEnum.Sucess, "Activity created"));
        }