示例#1
0
        public ResultsView()
        {
            InitializeComponent();

            textpad.Enter         += new EventHandler(DoGotFocus);
            textpad.Saving        += new EventHandler(DoSaving);
            textpad.TextChanged   += new EventHandler(DoTextChanged);
            textpad.ToggleResults += new EventHandler(DoToggleResults);
            grid.Enter            += new EventHandler(DoGotFocus);
            msgpad.Enter          += new EventHandler(DoGotFocus);
            msgpad.TextChanged    += new EventHandler(DoTextChanged);
            msgpad.ToggleResults  += new EventHandler(DoToggleResults);
            planView.Enter        += new EventHandler(DoGotFocus);
            statisticsView.Enter  += new EventHandler(DoGotFocus);

            tabset.TabPages.Remove(gridPage);
            tabset.TabPages.Remove(planPage);
            tabset.TabPages.Remove(statsPage);

            textPage.Selected = true;

            this.notepad      = textpad;
            this.resultTarget = ResultTarget.Text;
            this.resultCount  = 0;
            this.messageCount = 0;
        }
示例#2
0
        [OutputCache(NoStore = true, Duration = 0)] // do not cache generator calls
        public ContentResult GetByAlias(
            string displayAlias,
            SourceTypes sourceType    = SourceTypes.ContentItem,
            ResultTarget resultTarget = ResultTarget.Contents,
            string mfilter            = "",
            int page                = 1,
            int pageSize            = 10,
            bool tinyResponse       = true,
            bool minified           = false,
            bool realformat         = false,
            int deeplevel           = 10,
            string complexBehaviour = "")
        {
            //   Logger.Error("inizio"+DateTime.Now.ToString());
            IContent item = null;

            if (displayAlias.ToLower() == "user+info" || displayAlias.ToLower() == "user info")
            {
                // The call to this generator method is generally anonymous, but we still want to send out the json reflecting the structure of a user
                // so it can be mapped.
                // We are sending out the admin user, but this may end up being a security concern in some cases so:
                // TODO: figure out a way to not be sending out admin information here, since this call is anonymous.

                item = _orchardServices.ContentManager.Get(2);
            }
            else
            {
                var autoroutePart = _orchardServices.ContentManager.Query <AutoroutePart, AutoroutePartRecord>()
                                    .ForVersion(VersionOptions.Published)
                                    .Where(w => w.DisplayAlias == displayAlias).List().SingleOrDefault();

                if (autoroutePart != null && autoroutePart.ContentItem != null)
                {
                    item = autoroutePart.ContentItem;
                }
                else
                {
                    new HttpException(404, ("Not found"));
                    return(null);
                }
            }
            ContentResult cr = (ContentResult)GetContent(item, sourceType, resultTarget, mfilter, page, pageSize, tinyResponse, minified, realformat, deeplevel, complexBehaviour.Split(','));

            //    Logger.Error("Fine:"+DateTime.Now.ToString());

            if (_orchardServices.WorkContext.CurrentSite.As <WebServiceSettingsPart>().LogWebservice)
            {
                Logger.Error(cr.Content.ToString());
            }
            return(cr);
        }
        public DumperServiceContext(
            IContent content,
            Func <ObjectDumper> dumperConstructor,
            Action <XElement, StringBuilder> convertToJson,
            ResultTarget resultTarget,
            int page     = 1,
            int pageSize = 10)
        {
            Content       = content;
            GetDumper     = dumperConstructor;
            ConvertToJson = convertToJson;
            Page          = page;
            PageSize      = pageSize;

            ContentLists = new List <string>();
        }
示例#4
0
        static ResultTarget getResultCounts(Result r)
        {
            ResultTarget res = new ResultTarget();

            r.stdout.Seek(0, SeekOrigin.Begin);
            StreamReader reader = new StreamReader(r.stdout);

            while (!reader.EndOfStream)
            {
                string l = reader.ReadLine();                                                                            // does not contain \r\n
                l.TrimEnd(' ');
                if (l == "sat" || l == "SAT" || l == "SATISFIABLE" || l == "s SATISFIABLE" || l == "SuccessfulRuns = 1") // || l == "VERIFICATION FAILED")
                {
                    res.sat++;
                }
                else if (l == "unsat" || l == "UNSAT" || l == "UNSATISFIABLE" || l == "s UNSATISFIABLE") // || l == "VERIFICATION SUCCESSFUL")
                {
                    res.unsat++;
                }
                else if (l == "unknown" || l == "UNKNOWN" || l == "INDETERMINATE")
                {
                    res.other++;
                }
            }

            //Regex re = new Regex(@"\(restarts: ([0-9]+) flips: ([0-9]+) fps: ([0-9.]+)\)");

            //reader = new StreamReader(r.stderr);
            //r.stderr.Seek(0, SeekOrigin.Begin);
            //while (!reader.EndOfStream)
            //{
            //    Match m = re.Match(reader.ReadLine());
            //    if (m.Success)
            //        res.other += Convert.ToUInt32(m.Groups[2].Value);
            //}

            return(res);
        }
示例#5
0
        private void DoChangeResultsTarget(object sender, EventArgs e)
        {
            if (ResultTargetChanged == null)
            {
                return;
            }

            if (sender == textMenuItem)
            {
                this.ResultTarget = ResultTarget.Text;
            }
            else if (sender == gridMenuItem)
            {
                this.ResultTarget = ResultTarget.Grid;
            }
            else
            {
                this.ResultTarget = ResultTarget.Xml;
            }

            ResultTargetChanged(sender, new ResultTargetChangedEventArgs(this.ResultTarget));
            editorView.Focus();
        }
示例#6
0
        static ResultTarget getTarget(string filename)
        {
            ResultTarget res = new ResultTarget();

            try
            {
                FileStream   f = File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                StreamReader r = new StreamReader(f);

                while (!r.EndOfStream)
                {
                    string l = r.ReadLine(); // does not contain \r\n
                    if (l.StartsWith("(set-info :status sat)"))
                    {
                        res.sat++;
                    }
                    else if (l.StartsWith("(set-info :status unsat)"))
                    {
                        res.unsat++;
                    }
                    else if (l.StartsWith("(set-info :status"))
                    {
                        res.other++;
                    }
                }

                r.Close();
                f.Close();
            }
            catch (Exception)
            {
                // OK, this can happen for bogus filenames, etc.
            }

            return(res);
        }
示例#7
0
        void saveResult(Result r, ref SqlTransaction transaction)
        {
            int resultCode = 4; // ERROR

            ResultTarget target = new ResultTarget();
            ResultTarget result = new ResultTarget();

retry:
            try
            {
                target = getTarget(r.j.localFilename);
                result = getResultCounts(r);
            }
            catch (Exception ex)
            {
                if (logInfrastructureError(r.j, ex.Message + "\n" + ex.StackTrace))
                {
                    goto retry;
                }
                return;
            }

            if (r.exitCode == "TIME")
            {
                resultCode = 5; // TIMEOUT
            }
            else if (r.exitCode == "MEMORY")
            {
                resultCode = 6; // MEMORYOUT
            }
            else if (r.exitCode == "0" || r.exitCode == "10" || r.exitCode == "20")
            {
                resultCode = 0; // OK
                if (result.sat == 0 && result.unsat == 0 && result.other == 0)
                {
                    resultCode = 4; // ERROR
                }
            }
            else if (r.exitCode == "101")
            {
                resultCode = 6; // MEMORYOUT
            }
            else
            {
                resultCode = getBugCode(r);
            }

            string     exitCodeString = (r.exitCode == "TIME" || r.exitCode == "MEMORY") ? "NULL" : r.exitCode;
            SqlCommand cmd            = new SqlCommand("SRN " + r.j.experimentID + "," + r.j.ID + "," + r.j.filenameP + "," + exitCodeString + "," + resultCode + "," +
                                                       result.sat + "," + result.unsat + "," + result.other + "," + target.sat + "," + target.unsat + "," + target.other + "," +
                                                       r.runtime + ",@STDOUT,@STDERR,'" + myName + "';", sql, transaction);

            cmd.CommandTimeout = 0;

            SqlParameter out_param = cmd.Parameters.Add("@STDOUT", System.Data.SqlDbType.VarChar);
            SqlParameter err_param = cmd.Parameters.Add("@STDERR", System.Data.SqlDbType.VarChar);

            if (resultCode >= 3)
            {
                r.stdout.Seek(0, SeekOrigin.Begin);
                out_param.Value = new StreamReader(r.stdout).ReadToEnd();
                r.stderr.Seek(0, SeekOrigin.Begin);
                err_param.Value = new StreamReader(r.stderr).ReadToEnd();
            }
            else
            {
                out_param.Value = System.DBNull.Value;
                err_param.Value = System.DBNull.Value;
            }

            cmd.ExecuteNonQuery();

            infrastructure_errors_max = infrastructure_errors_init;
        }
 public ActionResult GetObjectById(int contentId = 0, SourceTypes sourceType = SourceTypes.ContentItem, ResultTarget resultTarget = ResultTarget.Contents, string mfilter = "", int page = 1, int pageSize = 1000, bool tinyResponse = true, bool minified = false, bool realformat = false, int deeplevel = 10, decimal version = 0)
 {
     if (contentId > 0)
     {
         IContent item = _orchardServices.ContentManager.Get(contentId, VersionOptions.Published);
         if (item == null)
         {
             Response rsp = _utilsServices.GetResponse(ResponseType.None, "Valore Id non valido");
             // rsp.Message = ;
             XmlSerializer serializer = new XmlSerializer(typeof(Response));
             XmlDocument   doc        = new XmlDocument();
             StringWriter  sww        = new StringWriter();
             XmlWriter     writer     = XmlWriter.Create(sww);
             serializer.Serialize(writer, rsp);
             var xml = sww.ToString();
             return(this.Content(xml, "text/xml"));
         }
         else
         {
             if (item.As <AutoroutePart>() != null)
             {
                 return(GetObjectByAlias(item.As <AutoroutePart>().DisplayAlias, sourceType, resultTarget, mfilter, page, pageSize, tinyResponse, deeplevel, version));
             }
             else
             {
                 Response rsp = _utilsServices.GetResponse(ResponseType.None);
                 rsp.Message = "Valore Id non valido";
                 XmlSerializer serializer = new XmlSerializer(typeof(Response));
                 XmlDocument   doc        = new XmlDocument();
                 StringWriter  sww        = new StringWriter();
                 XmlWriter     writer     = XmlWriter.Create(sww);
                 serializer.Serialize(writer, rsp);
                 var xml = sww.ToString();
                 return(this.Content(xml, "text/xml"));
             }
         }
     }
     else
     {
         Response rsp = _utilsServices.GetResponse(ResponseType.None);
         rsp.Message = "Valore Id non valido";
         XmlSerializer serializer = new XmlSerializer(typeof(Response));
         XmlDocument   doc        = new XmlDocument();
         StringWriter  sww        = new StringWriter();
         XmlWriter     writer     = XmlWriter.Create(sww);
         serializer.Serialize(writer, rsp);
         var xml = sww.ToString();
         return(this.Content(xml, "text/xml"));
     }
     //if (item == null) {
     //    new HttpException(404, ("Not found"));
     //    Response rsp = _utilsServices.GetResponse(ResponseType.None);
     //    rsp.Message = "Pagina non trovata";
     //    XmlSerializer serializer = new XmlSerializer(typeof(Response));
     //    XmlDocument doc = new XmlDocument();
     //    StringWriter sww = new StringWriter();
     //    XmlWriter writer = XmlWriter.Create(sww);
     //    serializer.Serialize(writer, rsp);
     //    var xml = sww.ToString();
     //    return this.Content(xml, "text/xml");
     //}
     //return (ContentResult)GetContent(item, sourceType, resultTarget, mfilter, page, pageSize, tinyResponse, minified, realformat, deeplevel);
 }
        private ActionResult GetContent(IContent content, SourceTypes sourceType = SourceTypes.ContentItem, ResultTarget resultTarget = ResultTarget.Contents, string fieldspartsFilter = "", int page = 1, int pageSize = 10, bool tinyResponse = true, bool minified = false, bool realformat = false, int deeplevel = 10, string[] complexBehaviour = null)
        {
            var result = new ContentResult {
                ContentType = "application/json"
            };
            var jsonString = "{}";

            var      _filterContentFieldsParts = fieldspartsFilter.ToLower().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            XElement dump;
            XElement projectionDump = null;
            // il dump dell'oggetto principale non filtra per field
            ObjectDumper    dumper = new ObjectDumper(deeplevel, null, false, tinyResponse, complexBehaviour);
            dynamic         shape; //, specificShape;
            var             sb          = new StringBuilder();
            List <XElement> listContent = new List <XElement>();

            // verifico se l'oggetto è soggetto all'accettazione delle policies
            var policy = content.As <Policy.Models.PolicyPart>();

            //if (policy != null) {
            //    if ((String.IsNullOrWhiteSpace(_orchardServices.WorkContext.HttpContext.Request.QueryString["v"]))) {// E' soggetto a privacy, quindi faccio sempre il redirect se manca il parametro in querystring v=
            //        if (policy.HasPendingPolicies ?? false) { // se ha delle pending policies deve restituire le policy text, legate al contenuto, qui ndi non deve mai servire cache
            //            var redirectUrl = String.Format("{0}{1}v={2}", _orchardServices.WorkContext.HttpContext.Request.RawUrl, (_orchardServices.WorkContext.HttpContext.Request.RawUrl.Contains("?") ? "&" : "?"), Guid.NewGuid());
            //            _orchardServices.WorkContext.HttpContext.Response.Redirect(redirectUrl, true);
            //        } else {// se NON ha delle pending policies deve restituire un url non cacheato (quindi aggiungo v=),
            //            var redirectUrl = String.Format("{0}{1}v={2}", _orchardServices.WorkContext.HttpContext.Request.RawUrl, (_orchardServices.WorkContext.HttpContext.Request.RawUrl.Contains("?") ? "&" : "?"), "cached-content");
            //            _orchardServices.WorkContext.HttpContext.Response.Redirect(redirectUrl, true);
            //            //_orchardServices.WorkContext.HttpContext.Response.Redirect(redirectUrl, true);
            //        }
            //        return null; // in entrambi i casi ritorno null come risultato della current request
            //    }
            //}
            if (policy != null && (_policyServices.HasPendingPolicies(content.ContentItem) ?? false))   // Se l'oggetto ha delle pending policies allora devo serivre la lista delle pending policies
            //policy.PendingPolicies
            {
                sb.Insert(0, "{");
                sb.AppendFormat("\"n\": \"{0}\"", "Model");
                sb.AppendFormat(", \"v\": \"{0}\"", "VirtualContent");
                sb.Append(", \"m\": [{");
                sb.AppendFormat("\"n\": \"{0}\"", "VirtualId"); // Unused property for mobile mapper needs
                sb.AppendFormat(", \"v\": \"{0}\"", "0");
                sb.Append("}]");

                sb.Append(", \"l\":[");

                int i = 0;
                sb.Append("{");
                sb.AppendFormat("\"n\": \"{0}\"", "PendingPolicies");
                sb.AppendFormat(", \"v\": \"{0}\"", "ContentItem[]");
                sb.Append(", \"m\": [");

                foreach (var item in _policyServices.PendingPolicies(content.ContentItem))
                {
                    if (i > 0)
                    {
                        sb.Append(",");
                    }
                    sb.Append("{");
                    dumper         = new ObjectDumper(deeplevel, _filterContentFieldsParts, false, tinyResponse, complexBehaviour);
                    projectionDump = dumper.Dump(item, String.Format("[{0}]", i));
                    JsonConverter.ConvertToJSon(projectionDump, sb, minified, realformat);
                    sb.Append("}");
                    i++;
                }
                sb.Append("]");
                sb.Append("}");

                sb.Append("]"); // l : [
                sb.Append("}");
            }
            else     // Se l'oggetto NON ha delle pending policies allora posso servire l'oggetto stesso
            {
                shape = _orchardServices.ContentManager.BuildDisplay(content);
                if (sourceType == SourceTypes.ContentItem)
                {
                    dump = dumper.Dump(content, "Model");
                }
                else
                {
                    dump = dumper.Dump(shape, "Model");
                }
                //dump.XPathSelectElements("");
                //var filteredDump = dump.Descendants();
                //ConvertToJSon(dump, sb);
                JsonConverter.ConvertToJSon(dump, sb, minified, realformat);
                sb.Insert(0, "{");
                sb.Append(", \"l\":[");
                // Dopo avere convertito il contentItem in JSON aggiungo i Json delle eventuali liste
                dynamic part                 = null;
                var     firstList            = true;
                var     listDumpedContentIds = new List <int>();

                #region [ProjectionPart ]

                try {
                    part = shape.ContentItem.ProjectionPart;
                } catch {
                    part = null;
                }
                if (part != null)
                {
                    if (!firstList)
                    {
                        sb.Append(",");
                    }
                    firstList = false;
                    var queryId    = part.Record.QueryPartRecord.Id;
                    var queryItems = _projectionManager.GetContentItems(queryId, (page - 1) * pageSize, pageSize);
                    int i          = 0;
                    sb.Append("{");
                    sb.AppendFormat("\"n\": \"{0}\"", "ProjectionList");
                    sb.AppendFormat(", \"v\": \"{0}\"", "ContentItem[]");
                    sb.Append(", \"m\": [");

                    foreach (var item in queryItems)
                    {
                        if (i > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append("{");
                        dumper         = new ObjectDumper(deeplevel, _filterContentFieldsParts, false, tinyResponse, complexBehaviour);
                        projectionDump = dumper.Dump(item, String.Format("[{0}]", i));
                        JsonConverter.ConvertToJSon(projectionDump, sb, minified, realformat);
                        sb.Append("}");
                        i++;
                    }
                    sb.Append("]");
                    sb.Append("}");
                }
                part = null;

                #endregion [ProjectionPart ]

                #region [CalendarPart ]

                try {
                    part = shape.ContentItem.CalendarPart;
                } catch {
                    part = null;
                }
                if (part != null)
                {
                    if (!firstList)
                    {
                        sb.Append(",");
                    }
                    firstList = false;
                    if (_orchardServices.WorkContext.TryResolve <IEventsService>(out _eventsService))  // non sempre questo modulo è attivo quindi se non riesce a risolvere il servizio, bypassa la chiamata
                    {
                        var queryItems = _eventsService.GetAggregatedList(part, page, pageSize);
                        int i          = 0;
                        sb.Append("{");
                        sb.AppendFormat("\"n\": \"{0}\"", "EventList");
                        sb.AppendFormat(", \"v\": \"{0}\"", "ContentItem[]");
                        sb.Append(", \"m\": [");

                        foreach (var item in queryItems)
                        {
                            if (i > 0)
                            {
                                sb.Append(",");
                            }
                            sb.Append("{");
                            dumper         = new ObjectDumper(deeplevel, _filterContentFieldsParts, false, tinyResponse, complexBehaviour);
                            projectionDump = dumper.Dump(item, String.Format("[{0}]", i));
                            JsonConverter.ConvertToJSon(projectionDump, sb);
                            sb.Append("}");
                            i++;
                        }
                        sb.Append("]");
                        sb.Append("}");
                    }
                }
                part = null;

                #endregion [CalendarPart ]

                #region [ExernalField]

                var ExtertalFields = (dynamic)
                                     (from parte in ((ContentItem)shape.ContentItem).Parts
                                      from field in parte.Fields
                                      where (field.GetType().Name == "FieldExternal" && ((dynamic)field).Setting.GenerateL)
                                      select field).FirstOrDefault();
                if (ExtertalFields != null)
                {
                    if (!firstList)
                    {
                        sb.Append(",");
                    }
                    firstList = false;
                    //sb.Append("{");
                    //sb.AppendFormat("\"n\": \"{0}\"", "ExternalContent");
                    //sb.AppendFormat(", \"v\": \"{0}\"", "ExternalContent");
                    //sb.Append(", \"m\": [");

                    sb.Append("{");
                    dumper = new ObjectDumper(deeplevel, _filterContentFieldsParts, false, tinyResponse, complexBehaviour);
                    //nameDynamicJsonArray = "List<generic>";
                    if (ExtertalFields.ContentObject != null)
                    {
                        if (ExtertalFields.ContentObject.GetType() == typeof(ExternalFieldRemoteException))
                        {
                            throw new ExternalFieldRemoteException();
                        }
                        projectionDump = dumper.Dump(cleanobj(ExtertalFields.ContentObject), ExtertalFields.Name, "List<generic>");
                        JsonConverter.ConvertToJSon(projectionDump, sb, minified, realformat);
                    }
                    //    sb.Append("}]}");
                    sb.Append("}");
                }

                #endregion [ExernalField]

                #region [ WidgetsContainerPart ]

                try {
                    part = shape.ContentItem.WidgetsContainerPart;
                } catch {
                    part = null;
                }
                if (part != null)
                {
                    //var queryId = part.Record.QueryPartRecord.Id;
                    if (_orchardServices.WorkContext.TryResolve <IWidgetManager>(out _widgetManager))  // non semepre questo modulo è attivo quindi se non riesce a risolvere il servizio, bypassa la chiamata
                    {
                        if (!firstList)
                        {
                            sb.Append(",");
                        }
                        firstList = false;
                        var queryItems = _widgetManager.GetWidgets(part.Id);
                        int i          = 0;
                        sb.Append("{");
                        sb.AppendFormat("\"n\": \"{0}\"", "WidgetList");
                        sb.AppendFormat(", \"v\": \"{0}\"", "ContentItem[]");
                        sb.Append(", \"m\": [");

                        foreach (var item in queryItems)
                        {
                            if (i > 0)
                            {
                                sb.Append(",");
                            }
                            sb.Append("{");
                            dumper         = new ObjectDumper(deeplevel, _filterContentFieldsParts, false, tinyResponse, complexBehaviour);
                            projectionDump = dumper.Dump(item, String.Format("[{0}]", i));
                            JsonConverter.ConvertToJSon(projectionDump, sb, minified, realformat);
                            sb.Append("}");
                            i++;
                        }
                        sb.Append("]");
                        sb.Append("}");
                    }
                }

                #endregion [ WidgetsContainerPart ]

                #region [ Taxonomy/TermsPart ]

                part = null;
                try {
                    if (shape.ContentItem.ContentType.EndsWith("Term") || !String.IsNullOrWhiteSpace(shape.ContentItem.TypeDefinition.Settings["Taxonomy"]))
                    {
                        part = shape.ContentItem.TermPart;
                    }
                } catch {
                    part = null;
                }
                if (part != null)
                {
                    if (!firstList)
                    {
                        sb.Append(",");
                    }
                    firstList = false;
                    dynamic termContentItems;
                    if (resultTarget == ResultTarget.Terms)
                    {
                        termContentItems = _taxonomyService.GetChildren(part, true);
                    }
                    else if (resultTarget == ResultTarget.SubTerms)
                    {
                        termContentItems = _taxonomyService.GetChildren(part, false);
                    }
                    else
                    {
                        termContentItems = _taxonomyService.GetContentItems(part, (page - 1) * pageSize, pageSize);
                    }

                    int i = 0;
                    sb.Append("{");
                    if (resultTarget == ResultTarget.Contents)
                    {
                        sb.AppendFormat("\"n\": \"{0}\"", "TaxonomyTermList");
                        sb.AppendFormat(", \"v\": \"{0}\"", "ContentItem[]");
                    }
                    else
                    {
                        sb.AppendFormat("\"n\": \"{0}\"", "TermPartList");
                        sb.AppendFormat(", \"v\": \"{0}\"", "TermPart[]");
                    }
                    sb.Append(", \"m\": [");

                    foreach (var item in termContentItems)
                    {
                        if (i > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append("{");
                        dumper = new ObjectDumper(deeplevel, _filterContentFieldsParts, false, tinyResponse, complexBehaviour);
                        if (resultTarget == ResultTarget.Contents)
                        {
                            projectionDump = dumper.Dump(item.ContentItem, String.Format("[{0}]", i));
                            JsonConverter.ConvertToJSon(projectionDump, sb, minified, realformat);
                        }
                        else
                        {
                            var dumperForPart = new ObjectDumper(deeplevel, _filterContentFieldsParts, true, tinyResponse, complexBehaviour);
                            projectionDump = dumperForPart.Dump(item, "TermPart");
                            JsonConverter.ConvertToJSon(projectionDump, sb, minified, realformat);
                        }
                        sb.Append("}");
                        i++;
                    }
                    sb.Append("]");
                    sb.Append("}");
                }
                part = null;

                #endregion [ Taxonomy/TermsPart ]

                sb.Append("]"); // l : [
                sb.Append("}");
            }
            jsonString     = sb.ToString().Replace("\t", " ");
            result.Content = jsonString;
            return(result);
        }
        public ContentResult GetById(int contentId, SourceTypes sourceType = SourceTypes.ContentItem, ResultTarget resultTarget = ResultTarget.Contents, string mfilter = "", int page = 1, int pageSize = 10, bool tinyResponse = true, bool minified = false, bool realformat = false, int deeplevel = 10, string complexBehaviour = "")
        {
            IContent item = _orchardServices.ContentManager.Get(contentId, VersionOptions.Published);

            if (item == null)
            {
                new HttpException(404, ("Not found"));
                return(null);
            }
            return((ContentResult)GetContent(item, sourceType, resultTarget, mfilter, page, pageSize, tinyResponse, minified, realformat, deeplevel, complexBehaviour.Split(',')));
        }
        public ActionResult GetByAlias(string displayAlias, SourceTypes sourceType = SourceTypes.ContentItem, ResultTarget resultTarget = ResultTarget.Contents, string mfilter = "", int page = 1, int pageSize = 10, bool tinyResponse = true, bool minified = false, bool realformat = false, int deeplevel = 10, string complexBehaviour = "")
        {
            //   Logger.Error("inizio"+DateTime.Now.ToString());
            IContent item = null;

            if (displayAlias == null)
            {
                return(Json(_utilsServices.GetResponse(ResponseType.MissingParameters), JsonRequestBehavior.AllowGet));
            }

            try {
                if (displayAlias.ToLower() == "user+info" || displayAlias.ToLower() == "user info")
                {
                    #region richiesta dati di uno user
                    var currentUser = _authenticationService.GetAuthenticatedUser();
                    if (currentUser == null)
                    {
                        //  return Content((Json(_utilsServices.GetResponse(ResponseType.InvalidUser))).ToString(), "application/json");// { Message = "Error: No current User", Success = false,ErrorCode=ErrorCode.InvalidUser,ResolutionAction=ResolutionAction.Login });
                        var result = new ContentResult {
                            ContentType = "application/json"
                        };
                        result.Content = Newtonsoft.Json.JsonConvert.SerializeObject(_utilsServices.GetResponse(ResponseType.InvalidUser));
                        return(result);
                    }
                    else
                    if (!_csrfTokenHelper.DoesCsrfTokenMatchAuthToken())
                    {
                        var result = new ContentResult {
                            ContentType = "application/json"
                        };
                        result.Content = Newtonsoft.Json.JsonConvert.SerializeObject(_utilsServices.GetResponse(ResponseType.InvalidXSRF));
                        return(result);
                        //   Content((Json(_utilsServices.GetResponse(ResponseType.InvalidXSRF))).ToString(), "application/json");// { Message = "Error: No current User", Success = false,ErrorCode=ErrorCode.InvalidUser,ResolutionAction=ResolutionAction.Login });
                    }
                    else
                    {
                        #region utente validato
                        item = currentUser.ContentItem;

                        #endregion
                    }
                    #endregion
                }
                else
                {
                    item = GetContentByAlias(displayAlias);
                }

                if (!_orchardServices.Authorizer.Authorize(Permissions.ViewContent, item))
                {
                    return(Json(UnauthorizedResponse(), JsonRequestBehavior.AllowGet));
                }

                if (item == null)
                {
                    return(new HttpStatusCodeResult(404));
                }

                ContentResult cr = (ContentResult)GetContent(item, sourceType, resultTarget, mfilter, page, pageSize, tinyResponse, minified, realformat, deeplevel, complexBehaviour.Split(','));
                //    Logger.Error("Fine:"+DateTime.Now.ToString());

                if (_orchardServices.WorkContext.CurrentSite.As <WebServiceSettingsPart>().LogWebservice)
                {
                    Logger.Error(cr.Content.ToString());
                }
                return(cr);
            } catch (System.Security.SecurityException) {
                return(Json(_utilsServices.GetResponse(ResponseType.InvalidUser), JsonRequestBehavior.AllowGet));
            } catch (OrchardSecurityException) {
                return(Json(UnauthorizedResponse(), JsonRequestBehavior.AllowGet));
            } catch {
                return(new HttpStatusCodeResult(500));
            }
        }
        public ActionResult GetObjectByAlias(string displayAlias, SourceTypes sourceType = SourceTypes.ContentItem, ResultTarget resultTarget = ResultTarget.Contents, string mfilter = "", int page = 1, int pageSize = 1000, bool tinyResponse = true, int deeplevel = 10, decimal version = 0)
        {
            try {
                if (page < 1)
                {
                    page = 1;
                }
                if (pageSize < 1)
                {
                    pageSize = 1000;
                }
                var autoroutePart = _orchardServices.ContentManager.Query <AutoroutePart, AutoroutePartRecord>()
                                    .ForVersion(VersionOptions.Published)
                                    .Where(w => w.DisplayAlias == displayAlias).List().SingleOrDefault();
                IContent item = null;
                if (autoroutePart != null && autoroutePart.ContentItem != null)
                {
                    item = autoroutePart.ContentItem;
                }
                else
                {
                    Response rsp = _utilsServices.GetResponse(ResponseType.None, "Pagina non trovata");

                    XmlSerializer serializer = new XmlSerializer(typeof(Response));
                    XmlDocument   doc        = new XmlDocument();
                    StringWriter  sww        = new StringWriter();
                    XmlWriter     writer     = XmlWriter.Create(sww);
                    serializer.Serialize(writer, rsp);
                    var xml = sww.ToString();
                    return(this.Content(xml, "text/xml"));
                    // return new HttpNotFoundResult();
                }

                List <dynamic> ListShape = new List <dynamic>();
                string         CiType    = "";
                if (item.ContentItem.ContentType == "ProjectionPage")
                {
                    #region Projection

                    var part = ((dynamic)item.ContentItem).ProjectionPart;
                    if (part != null)
                    {
                        var queryId = part.Record.QueryPartRecord.Id;

                        var queryItems = _projectionManager.GetContentItems(queryId, (page - 1) * pageSize, pageSize);

                        //   int i = 0;
                        if (queryItems.Count == 0)
                        {
                            return(null);
                        }
                        foreach (var projitem in queryItems)
                        {
                            // autoroutePart = projitem.AutoroutePart;
                            CiType = projitem.ContentType;
                            List <dynamic> list2 = ItemsMultiLanguage(projitem.AutoroutePart);
                            //  var merged = new List<dynamic>(ListShape);
                            ListShape.AddRange(list2.Where(p2 =>
                                                           ListShape.All(p1 => p1.ContentItem.Id != p2.ContentItem.Id)));
                            // ListShape = merged;
                        }

                        #endregion Projection
                    }
                }
                else
                {
                    //  string tipoCI = item.ContentItem.ContentType;
                    //   string CiType = ((ContentItem)autoroutePart.ContentItem).ContentType;
                    //  int id = ((ContentItem)autoroutePart.ContentItem).Id;

                    ListShape = ItemsMultiLanguage(autoroutePart);
                    CiType    = ((ContentItem)autoroutePart.ContentItem).ContentType;
                }

                //int masterid = 0;
                //int teoric_masterid = 0;
                //try {
                //    teoric_masterid = ((ContentItem)autoroutePart.ContentItem).As<LocalizationPart>().MasterContentItem.Id;
                //    masterid = teoric_masterid;
                //}
                //catch {
                //    masterid = id;
                //}
                //var contentsLocalized = _orchardServices.ContentManager.Query(CiType).Where<LocalizationPartRecord>(l => l.MasterContentItemId == masterid || l.Id == masterid).List();
                //List<dynamic> ListShape = new List<dynamic>();
                //foreach (ContentItem singleCi in contentsLocalized) {
                //    ListShape.Add(_orchardServices.ContentManager.BuildDisplay(singleCi));
                //}

                var namespaces = this.GetType().FullName.Split('.').AsEnumerable();
                namespaces = namespaces.Except(new string[] { this.GetType().Name });
                namespaces = namespaces.Except(new string[] { namespaces.Last() });
                var area = string.Join(".", namespaces);
                if (version > 0)
                {
                    CiType += version.ToString();
                }
                string myview = "~/" + @"App_Data/Sites/" + _shellSetting.Name + "/WebServices/" + CiType + ".cshtml";
                string myfile = HostingEnvironment.MapPath("~/") + @"App_Data\Sites\" + _shellSetting.Name + @"\WebServices\" + CiType + ".cshtml";
                if (System.IO.File.Exists(myfile))
                {
                    return(View(myview, (object)ListShape));
                }
                else
                {
                    Response rsp = _utilsServices.GetResponse(ResponseType.None, "Contenuto non disponibile");
                    //  rsp.Message =;
                    XmlSerializer serializer = new XmlSerializer(typeof(Response));
                    XmlDocument   doc        = new XmlDocument();
                    StringWriter  sww        = new StringWriter();
                    XmlWriter     writer     = XmlWriter.Create(sww);
                    serializer.Serialize(writer, rsp);
                    var xml = sww.ToString();
                    return(this.Content(xml, "text/xml"));
                }
            } catch (Exception ex) {
                Response rsp = _utilsServices.GetResponse(ResponseType.None, ex.Message);
                //   rsp.Message=;
                XmlSerializer serializer = new XmlSerializer(typeof(Response));
                XmlDocument   doc        = new XmlDocument();
                StringWriter  sww        = new StringWriter();
                XmlWriter     writer     = XmlWriter.Create(sww);
                serializer.Serialize(writer, rsp);
                var xml = sww.ToString();
                return(this.Content(xml, "text/xml"));
            }
        }
示例#13
0
        private ActionResult GetContent(
            IContent content,
            SourceTypes sourceType    = SourceTypes.ContentItem,
            ResultTarget resultTarget = ResultTarget.Contents,
            string fieldspartsFilter  = "",
            int page                  = 1,
            int pageSize              = 10,
            bool tinyResponse         = true,
            bool minified             = false,
            bool realformat           = false,
            int deeplevel             = 10,
            string[] complexBehaviour = null)
        {
            var result = new ContentResult {
                ContentType = "application/json"
            };
            var jsonString = "{}";

            var      _filterContentFieldsParts = fieldspartsFilter.ToLower().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            XElement dump;
            XElement projectionDump = null;
            // il dump dell'oggetto principale non filtra per field
            ObjectDumper dumper = new ObjectDumper(deeplevel, null, false, tinyResponse, complexBehaviour);
            var          sb     = new StringBuilder();

            // verifico se l'oggetto è soggetto all'accettazione delle policies
            var policy = content.As <Policy.Models.PolicyPart>();

            if (policy != null)
            {
                if ((String.IsNullOrWhiteSpace(_orchardServices.WorkContext.HttpContext.Request.QueryString["v"]))) // E' soggetto a privacy, quindi faccio sempre il redirect se manca il parametro in querystring v=
                {
                    if (policy.HasPendingPolicies ?? false)                                                         // se ha delle pending policies deve restituire le policy text, legate al contenuto, quindi non deve mai servire cache
                    {
                        var redirectUrl = String.Format("{0}{1}v={2}", _orchardServices.WorkContext.HttpContext.Request.RawUrl, (_orchardServices.WorkContext.HttpContext.Request.RawUrl.Contains("?") ? "&" : "?"), Guid.NewGuid());
                        _orchardServices.WorkContext.HttpContext.Response.Redirect(redirectUrl, true);
                    }
                    else    // se NON ha delle pending policies deve restituire un url non cacheato (quindi aggiungo v=),
                    {
                        var redirectUrl = String.Format("{0}{1}v={2}", _orchardServices.WorkContext.HttpContext.Request.RawUrl, (_orchardServices.WorkContext.HttpContext.Request.RawUrl.Contains("?") ? "&" : "?"), "cached-content");
                        _orchardServices.WorkContext.HttpContext.Response.Redirect(redirectUrl, true);
                        //_orchardServices.WorkContext.HttpContext.Response.Redirect(redirectUrl, true);
                    }
                    return(null); // in entrambi i casi ritorno null come risultato della current request
                }
            }
            if (policy != null && (policy.HasPendingPolicies ?? false))   // Se l'oggetto ha delle pending policies allora devo serivre la lista delle pending policies
            //policy.PendingPolicies
            {
                sb.Insert(0, "{");
                sb.AppendFormat("\"n\": \"{0}\"", "Model");
                sb.AppendFormat(", \"v\": \"{0}\"", "VirtualContent");
                sb.Append(", \"m\": [{");
                sb.AppendFormat("\"n\": \"{0}\"", "VirtualId"); // Unused property for mobile mapper needs
                sb.AppendFormat(", \"v\": \"{0}\"", "0");
                sb.Append("}]");

                sb.Append(", \"l\":[");

                int i = 0;
                sb.Append("{");
                sb.AppendFormat("\"n\": \"{0}\"", "PendingPolicies");
                sb.AppendFormat(", \"v\": \"{0}\"", "ContentItem[]");
                sb.Append(", \"m\": [");

                foreach (var item in policy.PendingPolicies)
                {
                    if (i > 0)
                    {
                        sb.Append(",");
                    }
                    sb.Append("{");
                    dumper         = new ObjectDumper(deeplevel, _filterContentFieldsParts, false, tinyResponse, complexBehaviour);
                    projectionDump = dumper.Dump(item, String.Format("[{0}]", i));
                    JsonConverter.ConvertToJSon(projectionDump, sb, minified, realformat);
                    sb.Append("}");
                    i++;
                }
                sb.Append("]");
                sb.Append("}");

                sb.Append("]"); // l : [
                sb.Append("}");
            }
            else     // Se l'oggetto NON ha delle pending policies allora posso servire l'oggetto stesso
            // Doing a IContentManager.Get here should ensure that the handlers that populate lazyfields
            // are executed, and all data in ContentParts and ContentField is initialized as it should.
            {
                content = _orchardServices.ContentManager.Get(content.Id, VersionOptions.Published);

                dump = dumper.Dump(content, "Model");

                JsonConverter.ConvertToJSon(dump, sb, minified, realformat);
                sb.Insert(0, "{");
                sb.Append(", \"l\":[");
                // Dopo avere convertito il contentItem in JSON aggiungo i Json delle eventuali liste

                var dumperContext = new DumperServiceContext(
                    content,
                    () =>
                    new ObjectDumper(deeplevel, _filterContentFieldsParts, false, tinyResponse, complexBehaviour),
                    (_xElement, _stringBuilder) =>
                    JsonConverter.ConvertToJSon(_xElement, _stringBuilder, minified, realformat),
                    resultTarget,
                    page, pageSize);
                foreach (var dumperService in _dumperServices)
                {
                    dumperService.DumpList(dumperContext);
                }
                sb.Append(string.Join(",", dumperContext.ContentLists));

                sb.Append("]"); // l : [
                sb.Append("}");
            }
            jsonString     = sb.ToString().Replace("\t", " ");
            result.Content = jsonString;
            return(result);
        }
示例#14
0
 public MiraeRuntimeResult(MiraeRuntimeResultType result, MiraeRuntimeError error, ResultTarget target)
 {
     Result = result;
     Error  = error;
     Target = target;
 }
示例#15
0
文件: Program.cs 项目: ahorn/z3test
        ResultTarget getTarget(string filename)
        {
            ResultTarget res = new ResultTarget();

            try
            {
                FileStream f = File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                StreamReader r = new StreamReader(f);

                while (!r.EndOfStream)
                {
                    string l = r.ReadLine(); // does not contain \r\n
                    if (l.StartsWith("(set-info :status sat)"))
                        res.sat++;
                    else if (l.StartsWith("(set-info :status unsat)"))
                        res.unsat++;
                    else if (l.StartsWith("(set-info :status"))
                        res.other++;
                }

                r.Close();
                f.Close();
            }
            catch (Exception)
            {
                // OK, this can happen for bogus filenames, etc.
            }

            return res;
        }
示例#16
0
文件: Program.cs 项目: ahorn/z3test
 ResultTarget getResultCounts(Result r)
 {
     ResultTarget res = new ResultTarget();
     r.stdout.Seek(0, SeekOrigin.Begin);
     StreamReader reader = new StreamReader(r.stdout);
     while (!reader.EndOfStream)
     {
         string l = reader.ReadLine(); // does not contain \r\n
         if (l == "sat" || l == "SAT" || l == "SATISFIABLE") // || l == "VERIFICATION FAILED")
             res.sat++;
         else if (l == "unsat" || l == "UNSAT" || l == "UNSATISFIABLE") // || l == "VERIFICATION SUCCESSFUL")
             res.unsat++;
         else if (l == "unknown" || l == "UNKNOWN" || l == "INDETERMINATE")
             res.other++;
     }
     return res;
 }
示例#17
0
 public ResultTargetChangedEventArgs(ResultTarget resultTarget)
 {
     this.resultTarget = resultTarget;
 }
示例#18
0
文件: Program.cs 项目: ExiaHan/z3test
        ResultTarget getResultCounts(Result r)
        {
            ResultTarget res = new ResultTarget();
            r.stdout.Seek(0, SeekOrigin.Begin);
            StreamReader reader = new StreamReader(r.stdout);
            while (!reader.EndOfStream)
            {
                string l = reader.ReadLine(); // does not contain \r\n
                l.TrimEnd(' ');
                if (l == "sat" || l == "SAT" || l == "SATISFIABLE" || l == "s SATISFIABLE" || l == "SuccessfulRuns = 1") // || l == "VERIFICATION FAILED")
                    res.sat++;
                else if (l == "unsat" || l == "UNSAT" || l == "UNSATISFIABLE" || l == "s UNSATISFIABLE") // || l == "VERIFICATION SUCCESSFUL")
                    res.unsat++;
                else if (l == "unknown" || l == "UNKNOWN" || l == "INDETERMINATE")
                    res.other++;
            }

            //Regex re = new Regex(@"\(restarts: ([0-9]+) flips: ([0-9]+) fps: ([0-9.]+)\)");

            //reader = new StreamReader(r.stderr);
            //r.stderr.Seek(0, SeekOrigin.Begin);
            //while (!reader.EndOfStream)
            //{
            //    Match m = re.Match(reader.ReadLine());
            //    if (m.Success)
            //        res.other += Convert.ToUInt32(m.Groups[2].Value);
            //}

            return res;
        }
示例#19
0
 public void DoResultTargetChanged(object sender, ResultTargetChangedEventArgs e)
 {
     this.ResultTarget = e.ResultTarget;
 }
示例#20
0
文件: Program.cs 项目: ahorn/z3test
        void saveResult(Result r, ref SqlTransaction t)
        {
            int resultCode = 4; // ERROR

            ResultTarget target = new ResultTarget();
            ResultTarget result = new ResultTarget();

            retry:
            try
            {
                target = getTarget(r.j.localFilename);
                result = getResultCounts(r);
            }
            catch (Exception ex)
            {
                if (logInfrastructureError(r.j, ex.Message + "\n" + ex.StackTrace))
                    goto retry;
                return;
            }

            if (r.exitCode == "TIME")
                resultCode = 5; // TIMEOUT
            else if (r.exitCode == "MEMORY")
                resultCode = 6; // MEMORYOUT
            else if (r.exitCode == "0") // || r.exitCode == "10" || r.exitCode == "20")
            {
                resultCode = 0; // OK
                if (result.sat == 0 && result.unsat == 0 && result.other == 0)
                    resultCode = 4; // ERROR
            }
            else if (r.exitCode == "101")
                resultCode = 6; // MEMORYOUT
            else
                resultCode = getBugCode(r);

            ensureConnected();
            string exitCodeString = (r.exitCode == "TIME" || r.exitCode == "MEMORY") ? "NULL" : r.exitCode;
            SqlCommand cmd = new SqlCommand("SRN " + r.j.experimentID + "," + r.j.ID + "," + r.j.filenameP + "," + exitCodeString + "," + resultCode + "," +
                                            result.sat + "," + result.unsat + "," + result.other + "," + target.sat + "," + target.unsat + "," + target.other + "," +
                                            r.runtime + ",@STDOUT,@STDERR,'" + myName + "';", sql, t);
            cmd.CommandTimeout = 0;

            SqlParameter out_param = cmd.Parameters.Add("@STDOUT", System.Data.SqlDbType.VarChar);
            SqlParameter err_param = cmd.Parameters.Add("@STDERR", System.Data.SqlDbType.VarChar);

            //if (true)
            if (resultCode >= 3)
            {
                r.stdout.Seek(0, SeekOrigin.Begin);
                out_param.Value = new StreamReader(r.stdout).ReadToEnd();
                r.stderr.Seek(0, SeekOrigin.Begin);
                err_param.Value = new StreamReader(r.stderr).ReadToEnd();
            }
            else
            {
                out_param.Value = System.DBNull.Value;
                err_param.Value = System.DBNull.Value;
            }

            cmd.ExecuteNonQuery();

            infrastructure_errors_max = infrastructure_errors_init;
        }
示例#21
0
        //========================================================================================
        // Add()
        //========================================================================================

        /// <summary>
        /// Displays the results of the given query.
        /// </summary>
        /// <param name="query">The query to report.</param>

        public void Add(Database.Query query)
        {
            Logger.WriteLine("Adding result with target [" + resultTarget + "]");

            Notepad msgTarget = textpad;

            if ((int)resultTarget < 0)                                          // TODO: why!?
            {
                resultTarget = ResultTarget.Text;
            }

            if (!query.HideResults)
            {
                if (query.QueryType == QueryType.SqlPlus)
                {
                    LoadFile(query.OutputFilename);
                }
                else
                {
                    switch (resultTarget)
                    {
                    case ResultTarget.Text:
                        ResultFormat format = (ResultFormat)UserOptions.GetEnumeration(
                            "results/general/format", typeof(ResultFormat));

                        if (format == ResultFormat.ColumnAligned)
                        {
                            ReportText(query);
                        }
                        else
                        {
                            ReportDelimitedText(query, format);
                        }
                        break;

                    case ResultTarget.Grid:
                        ReportGrid(query);
                        msgTarget = msgpad;
                        break;

                    case ResultTarget.Xml:
                        ReportXml(query);
                        break;
                    }
                }
            }

            if (query.Messages.Count > 0)
            {
                ReportMessages(query.Messages, msgTarget, query.HideResults);
            }
            else if (query.HideResults)
            {
                textpad.WriteNote(CR + RxNoMessages);
            }

            if (UserOptions.GetBoolean("results/general/dbmsOutput"))
            {
                if (query.OutputLines.Count > 0)
                {
                    ReportOutputLines(query.OutputLines);
                }
            }

            resultCount++;
        }